linking error

Bug #832334 reported by ichbinder
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lp-solve (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

When linking in C++ against this lib, I got linker errors for colamd and symamd:

/usr/lib/liblpsolve55.a(lp_MDO.o): In function `getMDO':
(.text+0x4fe): undefined reference to `colamd_recommended'
/usr/lib/liblpsolve55.a(lp_MDO.o): In function `getMDO':
(.text+0x550): undefined reference to `colamd_set_defaults'
/usr/lib/liblpsolve55.a(lp_MDO.o): In function `getMDO':
(.text+0x59b): undefined reference to `colamd'
/usr/lib/liblpsolve55.a(lp_MDO.o): In function `getMDO':
(.text+0x61c): undefined reference to `symamd'
collect2: ld returned 1 exit status

When I download the newest source from http://sourceforge.net/projects/lpsolve/files/lpsolve/5.5.2.0/lp_solve_5.5.2.0_source.tar.gz/download , compile it using the provided bash script ccc, and link against the build lib, my code compiles without linker errors.
If more information is needed, feel free to contact me.

Revision history for this message
Julian Taylor (jtaylor) wrote :

you appear to be wanting to link against the static version of liblpsolve
If you do this you need to explicitly link against colamd from the libcolamd2.7.1 package

It should not be required for dynamic linking against liblpsolve55.so as it will then pull it during runtime:
ldd -r /usr/lib/lp_solve/liblpsolve55.so
[...] libcolamd.so.2.7.1 => /usr/lib/libcolamd.so.2.7.1 (0x00007f10f7a6c000)

Changed in lp-solve (Ubuntu):
status: New → Invalid
Revision history for this message
Julian Taylor (jtaylor) wrote :

note the shared library is located in /usr/lib/lp_solve/ not /usr/lib
so you have to pass -L /usr/lib/lp_solve/ to your link command line that it pics it up.

Revision history for this message
ichbinder (my-crappy-spam) wrote :

Hey Julian,

you are absolutely right. When I exchange /usr/lib/liblpsolve55.a with /usr/lib/lp_solve/liblpsolve55.so, it compiles and links perfectly. I don't know why CMake didn't search for the dynamic version of liblpsolve but for the static one. I guess it just found the static one first as it lies directly in /usr/lib and not in a subdirectory?

Thanks for your time and help!
Manuel

Revision history for this message
Julian Taylor (jtaylor) wrote :

subdirectories of /usr/lib are not searched by default (except for arch triplets like x86_64-linux-gnu).
you have add the path to the linker search paths (-L flag on command line, link_directories in cmake)
when the path is added the linker should prefer the shared libraries over the static one.

Revision history for this message
Julian Taylor (jtaylor) wrote :

btw the reason why the shared library is in a subdirectory is because it is not versioned:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=503314
so you should keep in mind that when linking against the shared library your application can break or require a recompile when the library updates in a abi/api incompatible way.

for static libraries versioning is not necessary.

Revision history for this message
ichbinder (my-crappy-spam) wrote :

Hey Julian,

thanks for that information. I will try to keep that in mind, in case I run into problems like that...

Also thanks for your help!
Bye,
ichbinder

Revision history for this message
Yuteng Li (yutengl) wrote :

After I compile and link the program.
When I try to run the binary file it gives me
./prog7: error while loading shared libraries: liblpsolve55.so: cannot open shared object file: No such file or directory
What should I do with that?

Revision history for this message
ichbinder (my-crappy-spam) wrote :

Hi,

more information might be necessary to solve this. Where do you link to? /usr/lib/liblpsolve55.so? If so, the problem is probably already explained a few posts above by Julian: the shared library (ending with the extension ".so"; static libraries have ".a" as extension) is in a subdirectory in /usr/lib/, if installed regularly with Ubuntu's Software Center, Synaptic, make install, or similar default installation methods. In that case, you will have to link to the liblpsolve55.so in that subfolder!

Greetings,
Manuel

Revision history for this message
Julian Taylor (jtaylor) wrote :

also during runtime you have to tell the application where to find the shared library.
e.g. by setting LD_LIBRARY_PATH:
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}/usr/lib/lp_solve/
or by adding it to ld.so.conf
echo /usr/lib/lp_solve/ | sudo tee /etc/ld.so.conf.d/lpsolve

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.