ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a library of homegrown C functions;
I write stuff in C and C++
if I compile the library with g++, then gcc compiled sources won't link
and vice versa.
is there a way to get round this or do I need to make
two libraries, one for gcc and one for g++?
I don't see enough info in your post to be sure of what you are trying to do, but I have a good guess.
If you want functions that can be called from either C or C++, they must have a C interface. In C++ you use
Code:
extern "C"
to declare a C interface for a function (both for declaring an external function with C interface that is called here and defined elsewhere and for defining a function here with C interface to be called elsewhere).
You often need an include file that can declare the C interface and can be included in either C or C++ compiles. Usually that requires something like conditionally #defineing some symbol to be either nothing or "C" so it can be used every place a C interface must be predeclared with extern if including into a C module but with extern "C" if including into C++. Other cases may require two symbols, one for nothing vs. extern "C" { and the other for nothing vs. }
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.