dherity
Occasional contributor

How do I link C++ into a vendor daemon?

Jump to solution

I'd like to use C++ source code and libraries in a vendor daemon for Windows and Linux.

What do I need to do to achieve this?

Among other things, to do this we'd need to main() compiled as C++ rather than C and (in the case of gcc) to use g++ as the linker.

I don't see any support for this in the makefiles.

 

0 Kudos
1 Solution

Accepted Solutions
raffie
Intrepid explorer

Re: How do I link C++ into a vendor daemon?

Jump to solution

That info may be out of date.  I've never had a problem with this, and I do use static initialization for a couple variables.  I think Revenera uses gcc so I'm at least using the same compiler vendor.

I found this link that suggests that the issue with main might be old (in the "Linking the Program" section) but I've never actually heard of this issue before.   https://www.oracle.com/technical-resources/articles/it-infrastructure/mixing-c-and-cplusplus.html

You should probably just try it and see what happens.

 

View solution in original post

4 Replies
raffie
Intrepid explorer

Re: How do I link C++ into a vendor daemon?

Jump to solution

We do this.  You need to modify the makefile.  There probably isn't one simple change, though.  We changed some instances of CC to CXX (and defined CC to be gcc, which may or may not be necessary).  We also added some flags like -std=c++11 to one of the compile lines (but that was for compiling our own file).  You don't need to change all the targets, just the DAEMON target.  We didn't bother changing how lm_new or lsrvend were compiled.

The biggest issue is that you may need to ship the correct versions of the libstdc++  (and maybe libgcc_s) libraries on Linux.  Your customers won't always have them, or the correct versions.   To help with this we used the -rpath option when linking so that the vendor daemon would look in a specific relative directory, which is where we put the libraries.

We didn't need to change anything dealing with a main function.  I think it is in one of the static libraries that you link with.

dherity
Occasional contributor

Re: How do I link C++ into a vendor daemon?

Jump to solution

Thanks for the info. Its good to know this is being done successfully.

What you say makes sense, but I'm concerned about https://isocpp.org/wiki/faq/mixing-c-and-cpp, which says "You must use your C++ compiler when compiling main()(e.g., for static initialization) ". In a vendor daemon, main() is already compiled and we don't have the source code.

0 Kudos
raffie
Intrepid explorer

Re: How do I link C++ into a vendor daemon?

Jump to solution

That info may be out of date.  I've never had a problem with this, and I do use static initialization for a couple variables.  I think Revenera uses gcc so I'm at least using the same compiler vendor.

I found this link that suggests that the issue with main might be old (in the "Linking the Program" section) but I've never actually heard of this issue before.   https://www.oracle.com/technical-resources/articles/it-infrastructure/mixing-c-and-cplusplus.html

You should probably just try it and see what happens.

 

View solution in original post

dherity
Occasional contributor

Re: How do I link C++ into a vendor daemon?

Jump to solution

I certainly will.

Many thanks.

 

0 Kudos