Undefined reference to 'event_base_del_virtual' when compiling libfluid sample controller - c++

I'm trying to use libfluid to code my own OpenFlow controller. But first I want to build the sample controller to understand how that works.
I got the following error when compiling the sample controller:(this is the error I got when I try make msg_controller)
c++ msg/MsgController.cc -lfluid_msg -lfluid_base -I. -O3 -std=c++0x -o msg_controller
/usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/libfluid_base.so: undefined reference to `event_base_del_virtual'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/libfluid_base.so: undefined reference to `event_base_add_virtual'
collect2: error: ld returned 1 exit status
Makefile:10: recipe for target 'msg_controller' failed
make: *** [msg_controller] Error 1
Before building sample controller, I follow the steps to build libfluid_base and libfluid_msg. When building these two library I got the following prompt which I think might be helpful to solve my problem
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
during execution
add LIBDIR to the 'LD_RUN_PATH' environment variable
during linking
use the '-Wl,-rpath -Wl,LIBDIR' linker flag
have your system administrator add LIBDIR to '/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
Is the undefined reference error because the library not linking correctly?
Do I need to make some change to the c++ command?
I tried the command grep -rn "event_base_del" /usr/lib and also grep -rn "event_base_add" /usr/lib
The output for event_base_del is below (the same for event_base_add)
Binary file /usr/lib/libfluid_base.a matches
Binary file /usr/lib/libfluid_base.so.0.0.0 matches
Binary file /usr/lib/x86_64-linux-gnu/libevent.a matches
Binary file /usr/lib/x86_64-linux-gnu/libevent-2.1.so.6.0.2 matches
Binary file /usr/lib/x86_64-linux-gnu/libevent_core.a matches
Binary file /usr/lib/x86_64-linux-gnu/libevent_core-2.1.so.6.0.2 matches
Is this means it is linking correctly? since libfluid_base.so is just a link to libfluid_base.so.0.0.0
lrwxrwxrwx 1 root root 22 Oct 8 09:36 libfluid_base.so -> libfluid_base.so.0.0.0
So how can I fix this?
After I tried using -levent_core or -levnet to have the example code link against libevent. The error continue exist, it's probably because the version of libevent I'm using right now is not compatible with the current version of libfluid.By the way I'm using Ubuntu18.04.
I will try build it on ubuntu16.04 with older version of libevent see if it works.

event_base_del_virtual comes from libevent library. Link it with -levent_core.

Related

Hand built clang cannot find implicitly linked static library in Xcode default toolchain

As part of a research project I'm trying to use clang 6.0.1 with Xcode 9.4.1. I've built and installed clang in a custom location (/opt/llvm-6_0_1/clang). I wrote a simple xcplugin compiler specification to integrate my clang version with Xcode.
Now I can open projects in Xcode, select my proxy compiler and use it to build instead of Apple's default clang.
There were some minor additions that I had to make to the xcplugin's xcspec file to get this to work that probably won't be interesting to most people, so I won't provide the details here unless asked.
This all works with most of the projects I've played with, but I'm running into an odd problem where an implicitly linked static library cannot be found by my copy of clang. Specifically I get this error:
ld: file not found: /opt/llvm-6_0_1/clang/Toolchains/LLVM6.0.1.xctoolchain/usr/lib/arc/libarclite_macosx.a
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)
Note that the libarclite_macosx.a file is not explicitly included by the Xcode project. I figured it must be implicitly included, perhaps because this project enables ARC?
After pouring over the Xcode generated link command line (it's complex) I decided to look at the MyProject__dependency_info.dat file, which is passed in via the -dependency_info option. Apparently this data file (the path is defined as env var LD_DEPENDENCY_INFO_FILE) is created during the linking process, not as an input to the linker. Perhaps it exists because of a hack workaround using symlinks that I used to get a link to work (described at the end).
In any case the format appears to be binary, but I was able to see a text reference to libarclite_macosx.a in the file:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_macosx.a
After enabling the -Xlinker -v option I could see that my built clang was not searching the default toolchain lib or arc paths so I added them:
-L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib
-L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc
Now I can see the search paths in the verbose output, but clang still cannot find the library:
Library search paths:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc
I've tried adding the paths to the frameworks search paths. I also tried defining the various link path env vars. Nothing has worked.
To try to get a sense of what clang is actually doing, I used fs_usage while getting the link error:
sudo fs_usage -e -w -f filesys | grep "lib/arc"
14:11:00.461965 stat64 [ 2] /opt/llvm-6_0_1/clang/Toolchains/LLVM6.0.1.xctoolchain/usr/lib/arc>>>>>>>>>>>>>>>>>>>>>> 0.000006 ld.1421614
14:11:00.461968 stat64 [ 2] /opt/llvm-6_0_1/clang/Toolchains/LLVM6.0.1.xctoolchain/usr/lib/arc>>>>>>>>>>>>>>>>>>>>>> 0.000002 ld.1421614
Clearly clang really wants to look for this file in the installed location, not the location indicated in the -dependency_info, nor in the search paths that I'm providing.
At this stage the only way I can get a build to work is to add a symlink to Xcode's "arc" directory to my installed clang lib directory. That "works", but is fragile and nasty.
Any thoughts as to how how I can get clang find the static library where it actually lives?

error while loading shared libraries: libboost_serialization.so.1.66.0: cannot open shared object file: No such file or directory [duplicate]

There is a laptop on which I have no root privilege.
onto the machine I have a library installed using configure --prefix=$HOME/.usr .
after that, I got these files in ~/.usr/lib :
libXX.so.16.0.0
libXX.so.16
libXX.so
libXX.la
libXX.a
when I compile a program that invokes one of function provided by the library with this command :
gcc XXX.c -o xxx.out -L$HOME/.usr/lib -lXX
xxx.out was generated without warning, but when I run it error like this was thrown:
./xxx.out: error while loading shared libraries: libXX.so.16: cannot open shared object file: No such file or directory , though libXX.so.16 resides there.
my clue-less assumption is that ~/.usr/lib wasn't searched when xxx.out is invoked.
but what can I do to specify path of .so , in order that xxx.out can look there for .so file?
An addition is when I feed -static to gcc, another error happens like this:
undefined reference to `function_proviced_by_the_very_librar'
It seems .so does not matter even though -L and -l are given to gcc.
what should I do to build a usable exe with that library?
For other people who has the same question as I did
I found a useful article at tldp about this.
It introduces static/shared/dynamic loaded library, as well as some example code to use them.
There are two ways to achieve that:
Use -rpath linker option:
gcc XXX.c -o xxx.out -L$HOME/.usr/lib -lXX -Wl,-rpath=/home/user/.usr/lib
Use LD_LIBRARY_PATH environment variable - put this line in your ~/.bashrc file:
export LD_LIBRARY_PATH=/home/user/.usr/lib
This will work even for a pre-generated binaries, so you can for example download some packages from the debian.org, unpack the binaries and shared libraries into your home directory, and launch them without recompiling.
For a quick test, you can also do (in bash at least):
LD_LIBRARY_PATH=/home/user/.usr/lib ./xxx.out
which has the advantage of not changing your library path for everything else.
Should it be LIBRARY_PATH instead of LD_LIBRARY_PATH.
gcc checks for LIBRARY_PATH which can be seen with -v option

MINGW BOOST linking fails

I'm trying to compile this code using MINGW and BOOST
http://ttic.uchicago.edu/~cotter/projects/SBP/
First I compiled this under Linux/UBUNTu and no problem. Then I tried under W764 using MINGW64. Up to level of creating object all was OK but linking failed. Here is a command
g++ issvm_evaluate.o svm_kernel_base.o svm_kernel_private_cache.o
svm_optimizer_base.o svm_optimizer_classification_biased_perceptron.o
svm_optimizer_classification_biased_sbp.o
svm_optimizer_classification_biased_smo.o
svm_optimizer_classification_biased_sparsifier.o
svm_optimizer_classification_private_find_water_level.o
svm_optimizer_classification_unbiased_perceptron.o
svm_optimizer_classification_unbiased_sbp.o
svm_optimizer_classification_unbiased_smo.o
svm_optimizer_classification_unbiased_sparsifier.o -o issvm_evaluate -fopenmp
-LC:/boost_1_57_0/boost_1_57_0/bin.v2/libs/serialization/build/gcc-mingw-
4.9.0/release/ -lstdc++ -lm -LC:/boost_1_57_0/boost_1_570/bin.v2/libs/iostreams
/build\gcc-mingw-4.9.0/release/ -LC:/boost_1_57_0/boost_1_570/bin.v2
/libs/program_options/build/gcc-mingw-4.9.0/release/
and response
issvm_evaluate.o:issvm_evaluate.cpp:(.text+0x2a81): undefined reference to boos
t::archive::detail::archive_serializer_map<boost::archive::binary_iarchive>::era
se(boost::archive::detail::basic_serializer const*)'
issvm_evaluate.o:issvm_evaluate.cpp:(.text+0x2ac1): undefined reference to `boos
t::archive::detail::archive_serializer_map<boost::archive::binary_iarchive>::era
se(boost::archive::detail::basic_serializer const*)'
Make file from LINUX using l option in gcc but I couldn't find build libraries or
file ${patsubst %,-lboost_%,$(BOOST_LIBRARIES)} under LINUX so I suspect headers were just enough but under W7 i use L option and give directory to build libraries of boost. Any idea what the problem can be ??
As build directory of BOOST in W7 contains a lot of library files including dlls maybe l option of compiler should be used and linking to dll ??
I also tried with forward slashes but its the same
Seems that i fixed my problem. The problem was multiple using of -L option with different paths which don't give multiple search paths, only 1st -L is working. Additionally
library must be explicitly specified by -l option, setting just -L which points to correct directory with sub directories with libraries was not enough. Global setting of library path by LIBRARY_PATH environment variable is working so I replaced -L with this and copied all requested libraries to just one directory and specified by -l requested libraries.

Compliing C++ CGAL Module that is callable from Python

I am trying to compile some C++ code that is to be called from Python and then calls CGAL.
I need to be able to specify some flags on compilation, but not sure how to do this as the build process is
./CGAL-4.2/scripts/cgal_create_CMakeLists -s CallGCAL
cmake -DCGAL_DIR=./CGAL-4.2 .
make
And I don't want to have to hand edit the Makefile or CMakeLists
The error message I get from above without Flags to tell gcc it need Python are
CMakeFiles/CallGCAL.dir/CallGCAL.cpp.o: In function `initmyModule()':
CallGCAL.cpp:(.text+0x5e): undefined reference to `Py_InitModule4'
CMakeFiles/CallGCAL.dir/CallGCAL.cpp.o: In function `py_polygon(_object*, _object*)':
CallGCAL.cpp:(.text+0x86): undefined reference to `Py_BuildValue'
CMakeFiles/CallGCAL.dir/CallGCAL.cpp.o: In function `py_hull(_object*, _object*)':
CallGCAL.cpp:(.text+0xa6): undefined reference to `Py_BuildValue'
collect2: ld returned 1 exit status
Okay solved!!! Had to pass a variable to cmake.
Working script is as follows.
./CGAL-4.2/scripts/cgal_create_CMakeLists -s CallCGAL
cmake -DCGAL_DIR=./CGAL-4.2 -DCGAL_CXX_FLAGS="-shared -fPIC" .
make
rm -f CallCGAL.so
mv CallCGAL CallCGAL.so
Do I understand you correctly that want to compile your own code, which uses both Python and CGAL, with the aid of a makefile that comes with CGAL?
That is obviously impossible, since the CGAL makefile cannot know about Python. You must write your own makefile, which can be based on some existing makefiles, but also knows about Phython. The error you're reporting is generated by the loader which cannot find the Python library to resolve certain symbols. Thus, all you have to add to the makefile are the relevant -l and -L options.
The CMakeLists.txt created by cgal_create_CMakeLists is not at all designed for your use case. The created CMakeLists.txt tries to compile an executable, whereas you want to create a module. In the CMakeLists.txt, replace the line:
create_single_source_cgal_program(CallCGAL.cpp)
by:
add_library(CallCGAL MODULE CallCGAL.cpp)
target_link_libraries(CallCGAL ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} )
That way, CMake will create the correct Makefile, without any need to rename a file, or tweak the compilation and linking flags.

usr/bin/ld: cannot find -l<nameOfTheLibrary>

I'm trying to compile my program and it returns this error :
usr/bin/ld: cannot find -l<nameOfTheLibrary>
in my makefile I use the command g++ and link to my library which is a symbolic link to my library located on an other directory.
Is there an option to add to make it work please?
To figure out what the linker is looking for, run it in verbose mode.
For example, I encountered this issue while trying to compile MySQL with ZLIB support. I was receiving an error like this during compilation:
/usr/bin/ld: cannot find -lzlib
I did some Googl'ing and kept coming across different issues of the same kind where people would say to make sure the .so file actually exists and if it doesn't, then create a symlink to the versioned file, for example, zlib.so.1.2.8. But, when I checked, zlib.so DID exist. So, I thought, surely that couldn't be the problem.
I came across another post on the Internets that suggested to run make with LD_DEBUG=all:
LD_DEBUG=all make
Although I got a TON of debugging output, it wasn't actually helpful. It added more confusion than anything else. So, I was about to give up.
Then, I had an epiphany. I thought to actually check the help text for the ld command:
ld --help
From that, I figured out how to run ld in verbose mode (imagine that):
ld -lzlib --verbose
This is the output I got:
==================================================
attempt to open /usr/x86_64-linux-gnu/lib64/libzlib.so failed
attempt to open /usr/x86_64-linux-gnu/lib64/libzlib.a failed
attempt to open /usr/local/lib64/libzlib.so failed
attempt to open /usr/local/lib64/libzlib.a failed
attempt to open /lib64/libzlib.so failed
attempt to open /lib64/libzlib.a failed
attempt to open /usr/lib64/libzlib.so failed
attempt to open /usr/lib64/libzlib.a failed
attempt to open /usr/x86_64-linux-gnu/lib/libzlib.so failed
attempt to open /usr/x86_64-linux-gnu/lib/libzlib.a failed
attempt to open /usr/local/lib/libzlib.so failed
attempt to open /usr/local/lib/libzlib.a failed
attempt to open /lib/libzlib.so failed
attempt to open /lib/libzlib.a failed
attempt to open /usr/lib/libzlib.so failed
attempt to open /usr/lib/libzlib.a failed
/usr/bin/ld.bfd.real: cannot find -lzlib
Ding, ding, ding...
So, to finally fix it so I could compile MySQL with my own version of ZLIB (rather than the bundled version):
sudo ln -s /usr/lib/libz.so.1.2.8 /usr/lib/libzlib.so
Voila!
If your library name is say libxyz.so and it is located on path say:
/home/user/myDir
then to link it to your program:
g++ -L/home/user/myDir -lxyz myprog.cpp -o myprog
There does not seem to be any answer which addresses the very common beginner problem of failing to install the required library in the first place.
On Debianish platforms, if libfoo is missing, you can frequently install it with something like
apt-get install libfoo-dev
The -dev version of the package is required for development work, even trivial development work such as compiling source code to link to the library.
The package name will sometimes require some decorations (libfoo0-dev? foo-dev without the lib prefix? etc), or you can simply use your distro's package search to find out precisely which packages provide a particular file.
(If there is more than one, you will need to find out what their differences are. Picking the coolest or the most popular is a common shortcut, but not an acceptable procedure for any serious development work.)
For other architectures (most notably RPM) similar procedures apply, though the details will be different.
Compile Time
When g++ says cannot find -l<nameOfTheLibrary>, it means that g++ looked for the file lib{nameOfTheLibrary}.so, but it couldn't find it in the shared library search path, which by default points to /usr/lib and /usr/local/lib and somewhere else maybe.
To resolve this problem, you should either provide the library file (lib{nameOfTheLibrary}.so) in those search paths or use -L command option. -L{path} tells the g++ (actually ld) to find library files in path {path} in addition to default paths.
Example: Assuming you have a library at /home/taylor/libswift.so, and you want to link your app to this library. In this case you should supply the g++ with the following options:
g++ main.cpp -o main -L/home/taylor -lswift
Note 1: -l option gets the library name without lib and .so at its beginning and end.
Note 2: In some cases, the library file name is followed by its version, for instance libswift.so.1.2. In these cases, g++ also cannot find the library file. A simple workaround to fix this is creating a symbolic link to libswift.so.1.2 called libswift.so.
Runtime
When you link your app to a shared library, it's required that library stays available whenever you run the app. In runtime your app (actually dynamic linker) looks for its libraries in LD_LIBRARY_PATH. It's an environment variable which stores a list of paths.
Example: In case of our libswift.so example, dynamic linker cannot find libswift.so in LD_LIBRARY_PATH (which points to default search paths). To fix the problem you should append that variable with the path libswift.so is in.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/taylor
During compilation with g++ via make define LIBRARY_PATH if it may not be appropriate to change the Makefile with the -Loption. I had put my extra library in /opt/lib so I did:
$ export LIBRARY_PATH=/opt/lib/
and then ran make for successful compilation and linking.
To run the program with a shared library define:
$ export LD_LIBRARY_PATH=/opt/lib/
before executing the program.
First, you need to know the naming rule of lxxx:
/usr/bin/ld: cannot find -lc
/usr/bin/ld: cannot find -lltdl
/usr/bin/ld: cannot find -lXtst
lc means libc.so, lltdl means libltdl.so, lXtst means libXts.so.
So, it is lib + lib-name + .so
Once we know the name, we can use locate to find the path of this lxxx.so file.
$ locate libiconv.so
/home/user/anaconda3/lib/libiconv.so # <-- right here
/home/user/anaconda3/lib/libiconv.so.2
/home/user/anaconda3/lib/libiconv.so.2.5.1
/home/user/anaconda3/lib/preloadable_libiconv.so
/home/user/anaconda3/pkgs/libiconv-1.14-0/lib/libiconv.so
/home/user/anaconda3/pkgs/libiconv-1.14-0/lib/libiconv.so.2
/home/user/anaconda3/pkgs/libiconv-1.14-0/lib/libiconv.so.2.5.1
/home/user/anaconda3/pkgs/libiconv-1.14-0/lib/preloadable_libiconv.so
If you cannot find it, you need to install it by yum (I use CentOS). Usually you have this file, but it does not link to right place.
Link it to the right place, usually it is /lib64 or /usr/lib64
$ sudo ln -s /home/user/anaconda3/lib/libiconv.so /usr/lib64/
Done!
ref: https://i-pogo.blogspot.jp/2010/01/usrbinld-cannot-find-lxxx.html
When you compile your program you must supply the path to the library; in g++ use the -L option:
g++ myprogram.cc -o myprogram -lmylib -L/path/foo/bar
I had this problem with compiling LXC on a fresh VM with Centos 7.8. I tried all the above and failed. Some suggested removing the -static flag from the compiler configuration but I didn't want to change anything.
The only thing that helped was to install glibc-static and retry. Hope that helps someone.
Check the location of your library, for example lxxx.so:
locate lxxx.so
If it is not in the /usr/lib folder, type this:
sudo cp yourpath/lxxx.so /usr/lib
Done.
Apart from the answers already given, it may also be the case that the *.so file exists but is not named properly. Or it may be the case that *.so file exists but it is owned by another user / root.
Issue 1: Improper name
If you are linking the file as -l<nameOfLibrary>
then library file name MUST be of the form lib<nameOfLibrary>
If you only have <nameOfLibrary>.so file, rename it!
Issue 2: Wrong owner
To verify that this is not the problem - do
ls -l /path/to/.so/file
If the file is owned by root or another user, you need to do
sudo chown yourUserName:yourUserName /path/to/.so/file
Here is Ubuntu information of my laptop.
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
I use locate to find the .so files for boost_filesystem and boost_system
locate libboost_filesystem
locate libboost_system
Then link .so files to /usr/lib and rename to .so
sudo ln -s /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.65.1 /usr/lib/libboost_filesystem.so
sudo ln -s /usr/lib/x86_64-linux-gnu/libboost_system.so.1.65.1 /usr/lib/libboost_system.so
Done! R package velocyto.R was successfully installed!
This error may also be brought about if the symbolic link is to a dynamic library, .so, but for legacy reasons -static appears among the link flags. If so, try removing it.
The library I was trying to link to turned out to have a non-standard name (i.e. wasn't prefixed with 'lib'), so they recommended using a command like this to compile it -
gcc test.c -Iinclude lib/cspice.a -lm
I encountered the same error message.
I built the cmocka as a so and tried to link it to my executable.
But ld always complains below:
/usr/bin/ld: cannot find -lcmocka
It turns out that there are 3 files generated after cmocka is built:
libcmocka.so
libcmocka.so.0
libcmocka.so.0.7.0
1 and 2 are symbol links and only 3 is the real file.
I only copied the 1 to my library folder, where ld failed to find the 3.
After I copied all 3, ld works.