dreal/dreal3

C-API linking errors

Closed this issue · 2 comments

Dear dreal developers,

I succesfully compiled dReal on my Ubuntu 14.04 (64bit) following the instructions on the official page, i.e. running cmake and make (I have all the required versions for cmake, g++ and gcc). After that, I also executed make install to install the libraries in the Linux folders and I noticed the API libraries have been installed in /usr/include, /usr/lib and /usr/local/lib as expected.

After that, I tried to compile the basic_examples.cpp file provided in the scripts folder, but it does not work. It says:

basic_examples.cpp:(.text+0x2a): undefined reference to `dreal::solver::solver()'
basic_examples.cpp:(.text+0x48): undefined reference to `dreal::solver::var(char const*)'
basic_examples.cpp:(.text+0x65): undefined reference to `dreal::solver::num(double)'
basic_examples.cpp:(.text+0x8d): undefined reference to `dreal::expr::set_lb(double)'
basic_examples.cpp:(.text+0xb5): undefined reference to `dreal::expr::set_ub(double)'
...
...

Initially I also had problems because of the #include "dreal.h" because g++ was not able to find the header file. But, because of the /usr/include/dreal subfolder created by make install, I have just replaced the above directive with #include <dreal/dreal.h> and g++ found the library. But still, the library contains only the declarations of the solver and expr classes, whose methods should have been stored either in .cpp files or in .o or .so files, but the make install command did not install any of these files, so how can g++ load such classes?

The command I tried to use to compile basic_examples.cpp is:

g++ -o basic_examples -std=c++11 basic_examples.cpp

By using the pkg-config tool, I also tried to compile basic_example.cpp with the following command, which explicitly tells g++ which libraries should be loaded.

g++ -o letsee -std=c++11 -I/usr/local/include/dreal -L/usr/local/lib/dreal -ldreal -libex -ladept -lcapd -lClp -lCoinUtils -lbz2 -lz -llapack -lblas -lm -lnlopt -lglpk -lprim -lpicosat -lpthread -lm  basic_examples.cpp

... but I still get undefined reference errors because of inaccessible methods of the solver and expr classes.

What should I do to install dReal correctly? Have I missed/skipped some steps to install some shared libraries in /usr/lib ?

To confirm what I said above, the output from make install is below, you can see that only executables, header files and static libraries are copied in the system, and no .cpp, .o or .so files are installed.

-- Install configuration: "RELEASE"
-- Installing: /usr/local/lib/dreal
-- Installing: /usr/local/lib/dreal/libglpk.a
-- Installing: /usr/local/lib/dreal/libpicosat.a
-- Installing: /usr/local/lib/dreal/libcapd.la
-- Installing: /usr/local/lib/dreal/pkgconfig
-- Installing: /usr/local/lib/dreal/libdop.a
-- Installing: /usr/local/lib/dreal/libglpk.la
-- Installing: /usr/local/lib/dreal/libcapd.a
-- Installing: /usr/local/lib/dreal/libprim.la
-- Installing: /usr/local/lib/dreal/libprim.a
-- Installing: /usr/local/lib/dreal/libadept.a
-- Installing: /usr/local/lib/dreal/libadept.la
-- Installing: /usr/local/lib/dreal/libdreal.a
-- Installing: /usr/local/lib/dreal/libibex.a
-- Installing: /usr/local/include/dreal
-- Installing: /usr/local/include/dreal/dreal_control.h
-- Installing: /usr/local/include/dreal/dreal.h
-- Installing: /usr/local/include/dreal/dreal_c.h
-- Installing: /usr/local/lib/pkgconfig/dreal.pc
-- Installing: /usr/local/include/dreal/dreal_config.h
-- Installing: /usr/local/lib/dreal/dreal-config.cmake
-- Installing: /usr/local/lib/dreal/dreal-config-version.cmake
-- Installing: /usr/local/bin/dReal
-- Installing: /usr/local/bin/dOp
-- Installing: /usr/local/bin/dReach

Many thanks in advance for your support...

Hi @AndreaCallia, please try to have basic_examples.cpp before -l options for example:

g++-5 -o letsee -std=c++11 basic_examples.cpp <other options here>

Many thanks @soonho-tri this worked perfectly! Thanks again....