On Jan 1, 2011, at 7:06 AM, [email protected] wrote:
If I include the C++ header nlopt.hpp (version 2.2.1) in more than one source file, I keep getting "multiple definition" linker (gcc) errors of the form:
In function `nlopt::version(int&, int&, int&)':
nlopt.hpp:567: multiple definition of `nlopt::version(int&, int&, int&)'
nlopt.hpp:567: first defined here.

This is obviously due to the fact that some functions (namely srand, version, version_major, version_minor, version_bugfix, algorithm_name) are defined directly in the header. While the inclusion guards prevent the compiler from including the header multiple times in one compilation unit, the linker cannot handle the resulting multiple definitions.

Perhaps it would be better to either declare these functions inline or to define them in a separate source file?

Hi Peter,

Are you sure you are using NLopt version 2.2.1? Those functions are indeed declared inline in the 2.2.1 header file, and in fact this was one of the bugfixes in 2.2.1 (thanks to Steve Jaffe).

I just tried with g++ 4.3.2, and I'm able to #include nlopt.hpp in multiple source files linked into one program with no errors.

Steven


_______________________________________________
NLopt-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss

Reply via email to