This question already has answers here:
How to add "-l" (ell) compiler flag in CMake
(2 answers)
Closed 5 years ago.
I'm trying to write a simple program with PulseAudio lib. Everything is fine when it compiles under gcc (gcc -o name_one name_two.cpp -lpulse-simple -lpulse), but when I copy my program to cLion (under cmake) it throws up an error:
main.cpp:49: undefined reference to pa_simple_new
main.cpp:50: undefined reference to pa_strerror
main.cpp:78: undefined reference to pa_simple_drain
main.cpp:72: undefined reference to pa_simple_write
main.cpp:73: undefined reference to pa_strerror
main.cpp:79: undefined reference to pa_strerror
main.cpp:85: undefined reference to pa_simple_free
I've tried to add links (-lpulse-simple -lpulse) into my makeafile.txt like this:
add_compile_options(-lpulse-simple -lpulse)
but this is not working.
How to do it properly?
After adding
target_link_libraries("project name" pulse-simple pulse)
to my code, it was still occurating an error (library not found). I found on github this lines:
find_path(PULSEAUDIO_INCLUDE_DIR
NAMES pulse/pulseaudio.h
DOC "The PulseAudio include directory"
)
find_library(PULSEAUDIO_LIBRARY
NAMES pulse
DOC "The PulseAudio library"
)
and I added them to the file. Everything works fine, copy of my cmake file:
cmake_minimum_required(VERSION 3.8)
project(Audio)
set(CMAKE_CXX_STANDARD 11)
find_path(PULSEAUDIO_INCLUDE_DIR
NAMES pulse/pulseaudio.h
DOC "The PulseAudio include directory"
)
find_library(PULSEAUDIO_LIBRARY
NAMES pulse
DOC "The PulseAudio library"
)
include_directories(${PULSEAUDIO_INCLUDE_DIRS})
set(SOURCE_FILES main.cpp)
add_executable(Audio ${SOURCE_FILES})
target_link_libraries(Audio pulse-simple pulse)
Related
I want to play sound through opensl. Connected library Linker-> Input-> Library Dependencies - OpenSLES. The linker produces an error - undefined reference to slCreateEngine.
check your target_link_libraries method inside CmakeLists.txt if it has all the necessary libraries included..
target_link_libraries( # Specifies the target library.
native-lib
android
log
OpenSLES)
I was trying to convert an existed c++ project to CMake. The existed worked well with makefile, and i have converted similar one successfully. but when i try to convert this one, some confusing errors occurred, as below:
18:22:10: Running steps for project encryption...
18:22:10: Starting: "/export/opt/cmake-3.2.2/bin/cmake" --build . --target all
Linking CXX executable dist/Debug_64/GNU-Linux-x86/encryption
CMakeFiles/encryption.dir/encryption.cc.o: In function `main':
/export1/chao/nanos/nano_clean/nano_clean/src/encryption/encryption.cc:33: undefined reference to `stlp_std::cout'
...
/export1/chao/nanos/nano_clean/nano_clean/lib/STLport/stlport/stl/_string.c:604: undefined reference to `stlp_std::__stl_throw_out_of_range(char const*)'
...
At first i think it can't find iostream, so i include iostream at /export1/chao/nanos/nano_clean/nano_clean/lib/STLport/stlport/ by using 'INCLUDE_DIRECTORIES', but it did not work. Could you please give me some advices?
My CMakeLists.txt as below:
include_directories(/export1/chao/nanos/nano_clean/nano_clean/lib/STLport/stlport)
include_directories(/export1/chao/nanos/nano_clean/nano_clean/lib/STLport/stlport/h/using)
include_directories(/export1/chao/nanos/nano_clean/nano_clean/lib/boost/1.49.0/boost/tr1/tr1)
link_directories(
../common/dist/${CONF}/GNU-Linux-x86
/export2/chao/nanos/nano_built/lib/tiburonda/dist/include
)
aux_source_directory(. SRC_LIST)
include_directories(../common/include
)
add_executable(encryption ${SRC_LIST})
target_link_libraries(encryption libcommon.a)
According to original makefile, i found this project use source file encryption.cc at ./, header files: encryption.h at ./ and others at ../common/include.
I get a strange linker error when building a project (which uses GStreamer 1.0 and therefore depends on Glib 2.0) with cmake and linking against glib library. Glib is installed using macports, libglib-2.0.0.dylib is present in /opt/local/lib/. FindGLIB successfully finds its header files (compiling works) and also ${GLIB_LIBRARIES} provides the right path to the library.
The error message is
[100%] Linking CXX executable ../bin/presenter
Undefined symbols for architecture x86_64:
"_g_object_set", referenced from:
...
"_g_type_check_instance_cast", referenced from:
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
If I remove glib from the list completely it's also copmplaining about missing reference to g_print and g_printerr. Is it possible that the linking is done correctly but the functions are just missing for some reason inside the library?
How can I fix it?
Finally found my mistake. When using FindGLIB of the Webkit project, it by default searches only for the main glib library. It's components have to be passed in addition to be found:
find_package(GLIB COMPONENTS gobject REQUIRED)
would find glib itself and save it in ${GLIB_LIBRARIES} and also gobject and save it in ${GLIB_GOBJECT_LIBRARIES} so they can be used in target_link_libraries()
Reminder: Always read the comments in the file headers - they often contain useful information...
# Optionally, the COMPONENTS keyword can be passed to find_package()
# and Glib components can be looked for. Currently, the following
# components can be used, and they define the following variables if
# found:
#
# gio: GLIB_GIO_LIBRARIES
# gobject: GLIB_GOBJECT_LIBRARIES
# gmodule: GLIB_GMODULE_LIBRARIES
# gthread: GLIB_GTHREAD_LIBRARIES
I try to use a library compiled with gcc called matlisp based on fortran code. After specifyng the f77 compiler, I could performed the autoreconf, configure and make command to obtain the file libmatlisp.so.
But when I try to use it i get a:
Error opening shared object ".../libmatlisp.so":
/usr/lib/libf2c.so.2: undefined symbol: MAIN__.
And when i perform the command ld libmatlisp.so i get:
...
libmatlisp.so: undefined reference to `idamax_'
libmatlisp.so: undefined reference to `dger_'
/usr/lib/libf2c.so.2: undefined reference to `MAIN__'
libmatlisp.so: undefined reference to `zscal_'
libmatlisp.so: undefined reference to `dscal_'
....
Is there a way to improve the situation?
I already try this solution but it does not work.
I also try to change the compiler to gfortran but i get some some run time error messages mentionning missing libraries that are part of libf2c.
Ok. I move to a more recent source of matlisp 2012 instead of 2003, and it run properly in my environment now.
I have a question regarding the inclusion of boost libraries to make files. This question has been asked (and answered) multiple times in this forum and others, I could not solve my problem however using suggestions from there, since I am stuck in a much more basic stage.
I am using a ready made make file that includes the address of the boost libraries via an env file that is included in the beginning of the makefile. Thus, all I have to do is provide the correct folder of the boost libraries, however I seem to be providing the wrong address, as I get an error that the boost libraries could not be found:.
Demo_00.cpp:(.text+0x28): undefined reference to `boost::mpi::environment::environment(int&, char**&, bool)'
Demo_00.cpp:(.text+0x34): undefined reference to `boost::mpi::communicator::communicator()'
Demo_00.cpp:(.text+0x40): undefined reference to `boost::mpi::communicator::rank() const'
Demo_00.cpp:(.text+0x55): undefined reference to `boost::mpi::communicator::rank() const'
Demo_00.cpp:(.text+0x8b): undefined reference to `boost::mpi::environment::~environment()'
Demo_00.cpp:(.text+0xb3): undefined reference to `boost::mpi::environment::~environment()'
collect2: ld returned 1 exit status
The specific part of the env file looks like this:
BOOST_INCLUDE=-I./home/user/Documents/RHPC_2.0/INSTALLATION/boost_1_54_0/
BOOST_LIB_DIR=-L./home/user/Documents/RHPC_2.0/INSTALLATION/boost_1_54_0/stage/lib
BOOST_LIBS=-lboost_mpi-xgcc42-mt -lboost_serialization-xgcc42-mt -lboost_system-xgcc42-mt -lboost_filesystem-xgcc42-mt
My questions:
In the template file of the env file, the first address ended with '.../boost_1_54_0/include', my boost folder does not have an include folder however (there are some further within the folder only). Is this a problem?
Do I need to make any adjustment to BOOST_LIBS?
Is there maybe a simple way of identifying the correct addresses using cmake? I worked my way through the cmake documentary but did not quite get how this would be implemented.
Also: I have just tried to 'compile+link' by hand, which only worked for the compiling part but not for linking. Here is the compiling:
/home/user/Documents/RHPC_2.0/INSTALLATION/mpich2-1.4.1p1/bin/mpicxx -c -I/home/user/Documents/RHPC_2.0/INSTALLATION/boost_1_54_0/ -o Demo_00.o Demo_00.cpp
Here is the Linking part, which did not work
/home/user/Documents/RHPC_2.0/INSTALLATION/mpich2-1.4.1p1/bin/mpicxx -L/home/user/Documents/RHPC_2.0/INSTALLATION/boost_1_54_0/stage/lib/ Demo_00.cpp -lboost_mpi-xgcc42-mt -lboost_serialization-xgcc42-mt -lboost_system-xgcc42-mt -lboost_filesystem-xgcc42-mt
After this command I get the following error:
/usr/bin/ld: cannot find -lboost_mpi-xgcc42-mt
/usr/bin/ld: cannot find -lboost_serialization-xgcc42-mt
/usr/bin/ld: cannot find -lboost_system-xgcc42-mt
/usr/bin/ld: cannot find -lboost_filesystem-xgcc42-mt
collect2: ld returned 1 exit status
It seems, here the problem lies with the these last 4 files and not the entire boost folders. The above folders /usr/bin/ld are also not existent to my knowledge.
I appreciate your help and again my apologies for bringing up this topic yet again.
Thanks,
Tartaglia
Whatever is passed to -I should be pointing to the folder having boost/*hpp files under it (say boost/shared_ptr.hpp).
Whatever is passed to -L should be the folder where all of those passed to -l reside (when you say -lthename the respective file name is libthename.so).
Also these BOOST_* environment variables should be concatenated to the compiler/linker command line (I assume that is already happening automatically in your case).