[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Problem linking against coinor-symphony libraries



On Mon, Apr 27, 2015 at 11:56:46AM +0530, Kumar Appaiah wrote:
> Hi.
> 
> I am trying to link against a library that calls functions in another
> library (in this case, coinor-symphony, the a mixed integer linear
> programming solver). However, I keep running into an undefined symbols
> error. Mysteriously, it works when I directly compile the object files
> together, rather than build a library anbd link against that library.
> 
> A small test case is here:
> 
> http://www.ee.iitb.ac.in/~akumar/dump/libtest.tar.gz
> 
> Here is what you get if you run make:
> 
> gcc -Wall -fopenmp -c -o milp.o milp.c
> gcc -Wall -fopenmp -fPIC -c -o symtest.o symtest.c -I/usr/include/coin
> gcc -Wall -fPIC -fopenmp -shared -Wl,--rpath -Wl,/usr/lib -o
> libsymtest.so symtest.o `pkg-config --libs symphony`
> g++ -Wall -fopenmp -o milp milp.o `pkg-config --libs symphony`
> -L. -lsymtest
> ./libsymtest.so: undefined reference to `sym_parse_command_line'
> ./libsymtest.so: undefined reference to `sym_close_environment'
> ./libsymtest.so: undefined reference to `sym_load_problem'
> ./libsymtest.so: undefined reference to `sym_solve'
> ./libsymtest.so: undefined reference to `sym_open_environment'
> collect2: error: ld returned 1 exit status
> Makefile:4: recipe for target 'milp' failed
> make: *** [milp] Error 1
> 
> But if I try to do this, I can compile and run things:
> 
> g++ -c `pkg-config --cflags symphony` milp.c
> g++ -c `pkg-config --cflags symphony` symtest.c
> g++ -fopenmp milp.o symtest.o -o milp `pkg-config --libs symphony`
> 
> things work perfectly.
> 
> Could you please point out what I am missing? And this problem seems
> to occur only with the symphony libraries; linking against other
> libraries (notably ones that don't require fopenmp) seem to go through
> fine.

It turns out that I was trying to mix C code and C++ code, and I had
put the declaration of the C++ symphony functions within an extern "C"
block. So, just moving #include "symphony.h" outside the extern "C"
block fixed things.

Thanks.

Kumar
-- 
Linux, the way to get rid of boot viruses
		-- MaDsen Wikholm, mwikholm@at8.abo.fi


Reply to: