Cannot find lpublic library - c++

Trying to compile my project on Centos 8.2 using cmake 3.12, im facing with the following error:
cannot find -lpublic
here is full log:
[ 20%] Building CXX object CMakeFiles/ .cpp.o
[ 40%] Building CXX object CMakeFiles/ .cpp.o
[ 60%] Linking CXX shared library .so
[ 60%] Built target myproj
Scanning dependencies of target nist01
[ 80%] Building CXX object CMakeFiles/ .cpp.o
[100%] Linking CXX executable
/usr/bin/ld: cannot find -lpublic
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/nist01.dir/build.make:85: ...] Error 1
make[1]: *** [CMakeFiles/Makefile2:105: CMakeFiles/...] Error 2
make: *** [Makefile:84: all] Error 2
Tried to find something on the internet, but nothing shown up.
Thanks for your help.

That seems like you try to link against the target "public", which is a suspicious target name. It might be target_link_libraries command with lowercase public instead of uppercase one, like target_link_libraryies(nist01 public something) instead of target_link_libraries(nist01 PUBLIC something).

Related

CMake issues with target_include directories

I'm working on a new project, and trying to set up cmake from the ground up for the first time. I have two libraries that get built as targets in my project; libnet and liberror. I am linking libnet with liberror when I build the libnet target, and want to be able to #include header files that exist within liberror. I have the following added to the CMakeLists.txt for liberror:
target_include_directories(liberror SYSTEM PUBLIC core/error)
Now, I have the following added to the CMakeLists.txt for libnet:
target_link_libraries(libnet
PUBLIC
liberror)
So, liberror provides a header called ExceptionBuilder.hpp. When I try to do the following from libnet:
#include <core/error/ExceptionBuilder.hpp>
I get this error:
fatal error: core/error/ExceptionBuilder.hpp: No such file or directory
3 | #include <core/error/ExceptionBuilder.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I am quite new to cmake, so probably just setting something up incorrectly here, but any ideas? Here is the project structure:
Project Structure
Here is the verbose build output:
nmcurtis#DESKTOP-JC26375:~/distro/build$ make
-- Boost version: 1.58.0
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nmcurtis/distro/build
Consolidate compiler generated dependencies of target distro_core_error_objects
[ 11%] Built target distro_core_error_objects
Consolidate compiler generated dependencies of target distro_core_utility_objects
[ 16%] Built target distro_core_utility_objects
[ 22%] Linking CXX shared library libdistro_core_utility.so
/usr/local/gcc-11.3.0/bin/g++-11.3 -fPIC -fPIC -Wno-terminate -shared -Wl,-soname,libdistro_core_utility.so -o libdistro_core_utility.so CMakeFiles/distro_core_utility_objects.dir/Concepts.cpp.o
[ 22%] Built target distro_core_utility
[ 27%] Linking CXX shared library libdistro_core_error.so
/usr/local/gcc-11.3.0/bin/g++-11.3 -fPIC -fPIC -Wno-terminate -shared -Wl,-soname,libdistro_core_error.so -o libdistro_core_error.so CMakeFiles/distro_core_error_objects.dir/Exception.cpp.o CMakeFiles/distro_core_error_objects.dir/ExceptionBuilder.cpp.o -Wl,-rpath,/home/nmcurtis/distro/build/core/utility: ../utility/libdistro_core_utility.so
[ 27%] Built target distro_core_error
[ 33%] Linking CXX static library libdistro_core_utility_static.a
/usr/bin/ar qc libdistro_core_utility_static.a CMakeFiles/distro_core_utility_objects.dir/Concepts.cpp.o
/usr/bin/ranlib libdistro_core_utility_static.a
[ 33%] Built target distro_core_utility_static
[ 38%] Linking CXX static library libdistro_core_error_static.a
/usr/bin/ar qc libdistro_core_error_static.a CMakeFiles/distro_core_error_objects.dir/Exception.cpp.o CMakeFiles/distro_core_error_objects.dir/ExceptionBuilder.cpp.o
/usr/bin/ranlib libdistro_core_error_static.a
[ 38%] Built target distro_core_error_static
Consolidate compiler generated dependencies of target distro_core_net_objects
[ 44%] Building CXX object core/net/CMakeFiles/distro_core_net_objects.dir/Address.cpp.o
/home/nmcurtis/distro/core/net/Address.cpp:4:10: fatal error: core/error/ExceptionBuilder.hpp: No such file or directory
4 | #include <core/error/ExceptionBuilder.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
core/net/CMakeFiles/distro_core_net_objects.dir/build.make:120: recipe for target 'core/net/CMakeFiles/distro_core_net_objects.dir/Address.cpp.o' failed
make[2]: *** [core/net/CMakeFiles/distro_core_net_objects.dir/Address.cpp.o] Error 1
CMakeFiles/Makefile2:262: recipe for target 'core/net/CMakeFiles/distro_core_net_objects.dir/all' failed
make[1]: *** [core/net/CMakeFiles/distro_core_net_objects.dir/all] Error 2
Makefile:135: recipe for target 'all' failed
make: *** [all] Error 2
nmcurtis#DESKTOP-JC26375:~/distro/build$
If you do target_include_directories(liberror SYSTEM PUBLIC core/error) you do not need core/error in #include <core/error/ExceptionBuilder.hpp>
Do this in core/error/CMakeLists.txt.
target_include_directories(liberror SYSTEM PUBLIC .)
# or
# target_include_directories(liberror SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
#include "ExceptionBuilder.hpp"
If you wish #include "core/error/ExceptionBuilder.hpp" then
do this in core/error/CMakeLists.txt.
target_include_directories(liberror SYSTEM PUBLIC ../..)
# or
# target_include_directories(liberror SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../..)

cmake error when i have tried to build a compilining?

i have tried to compline a repository via "https://github.com/giglio0/DRAGON-G4-LaBr3.git" but while the compiling, i have taken a error. I don't Know why it is? i am not a coder. Just i want to build this repository and run the simulation with changing some parameters. The error output is;
Scanning dependencies of target LaBr3_v4
[ 9%] Building CXX object CMakeFiles/LaBr3_v4.dir/LaBr3_v4.cc.o
[ 18%] Building CXX object CMakeFiles/LaBr3_v4.dir/src/DetectorConstruction.cc.o
[ 27%] Building CXX object CMakeFiles/LaBr3_v4.dir/src/DetectorMessenger.cc.o
[ 36%] Building CXX object CMakeFiles/LaBr3_v4.dir/src/EventAction.cc.o
[ 45%] Building CXX object CMakeFiles/LaBr3_v4.dir/src/HistoManager.cc.o
/home/cancan/Gatev9/example_Geant4/LaBr/LaBr3/src/HistoManager.cc:29:10: fatal error: TH1D.h: No such file or directory
29 | #include <TH1D.h>
| ^~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/LaBr3_v4.dir/build.make:134: CMakeFiles/LaBr3_v4.dir/src/HistoManager.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/LaBr3_v4.dir/all] Error 2
make: *** [Makefile:149: all] Error 2
can anybody help me?
Apparently you need to install the ROOT library, see: https://root.cern.ch/doc/master/classTH1.html
BTW, the READ.me of the application you want to compile, DRAGON-G4-LaBr3, is awful.
After your advice, i install root-6.22.06 again with use this command;
cmake -DCMAKE_INSTALL_PREFIX=/home/cancan/Gatev9/root-6.22.06-install /home/cancan/Gatev9/root-6.22.06 -Dall=ON
i learned from somewhere if i use "-Dall=ON", i can install all libraries of root but it has not still worked.

CMake linker cannot find library that does not begin with "lib"

I am using CMake to compile an application which uses the HSImage library on github. After installing with pip, the HSI library generates a shared library file, in my case it is created at /usr/src/HSI/HSI.cpython-36m-aarch64-linux-gnu.so
I am trying to link this library to my application with CMake, but the CMake find_library method is having some trouble finding the library. Here is the relevant part of my CMakeLists.txt file:
CMakeLists.txt
set(HSI_DIR /usr/src/HSI)
find_library(HSI_LIB HSI.cpython-36m-aarch64-linux-gnu PATHS ${HSI_DIR})
message(STATUS "HSI: ${HSI_LIB}") # outputs /usr/src/HSI/HSI.cpython-36m-aarch64-linux-gnu.so
add_executable(${TARGET_NAME} <sources...>)
target_link_directories(${TARGET_NAME} PUBLIC ${HSI_DIR})
target_link_libraries(${TARGET_NAME}
${HSI_LIB}
<other libs...>
-Wl,--unresolved-symbols=ignore-in-shared-libs
)
When building, this produces the following error message:
cd /home/nvidia/projects/HsiInference/build;/usr/local/bin/cmake --build "/home/nvidia/projects/HsiInference/build" --target hsi_inference_onnx -- ;
Scanning dependencies of target hsi_inference_onnx
[ 14%] Building CXX object CMakeFiles/hsi_inference_onnx.dir/targets/HsiInferenceOnnx/main_onnx.cpp.o
[ 28%] Building CXX object CMakeFiles/hsi_inference_onnx.dir/targets/HsiInferenceOnnx/HsiInferenceOnnx.cpp.o
[ 42%] Building CXX object CMakeFiles/hsi_inference_onnx.dir/src/ftpnano.cpp.o
[ 57%] Building CXX object CMakeFiles/hsi_inference_onnx.dir/src/getOptions.cpp.o
[ 71%] Building CXX object CMakeFiles/hsi_inference_onnx.dir/src/logger.cpp.o
[ 85%] Building CXX object CMakeFiles/hsi_inference_onnx.dir/src/utils.cpp.o
[100%] Linking CXX executable hsi_inference_onnx_debug
CMakeFiles/hsi_inference_onnx.dir/build.make:245: recipe for target 'hsi_inference_onnx_debug' failed
CMakeFiles/Makefile2:123: recipe for target 'CMakeFiles/hsi_inference_onnx.dir/all' failed
**/usr/bin/ld: cannot find -lHSI.cpython-36m-aarch64-linux-gnu**
**collect2: error: ld returned 1 exit status**
make[3]: *** [hsi_inference_onnx_debug] Error 1
make[2]: *** [CMakeFiles/hsi_inference_onnx.dir/all] Error 2
CMakeFiles/Makefile2:130: recipe for target 'CMakeFiles/hsi_inference_onnx.dir/rule' failed
make[1]: *** [CMakeFiles/hsi_inference_onnx.dir/rule] Error 2
Makefile:196: recipe for target 'hsi_inference_onnx' failed
make: *** [hsi_inference_onnx] Error 2
Build failed.
The important part:
/usr/bin/ld: cannot find -lHSI.cpython-36m-aarch64-linux-gnu
collect2: error: ld returned 1 exit status
From what I have gathered, target_link_libraries simply adds -l<library_name> to the link command, and -l<library_name> assumes that there is a file called lib<library_name>.so to link, which is not the case here. How can I get CMake to link the library properly despite the weird filename?
NOTE:
I am able to get the project to build by doing the following:
Delete the project's build directory to clear CMake caches
Rename the file or create a symbolic link to libhsi.so
Change CMakeLists.txt to find_library(HSI_LIB hsi PATHS ${HSI_DIR})
This changes the link command to -lhsi instead, which is able to find the renamed/soft-linked library file. HOWEVER, this is not ideal for me and the original question remains unanswered :)
For libraries with weird filename you should add : before the filename. Be careful, like mentioned in https://linux.die.net/man/1/ld : If namespec is of the form :filename, ld will search the library path for a file called filename, otherwise it will search the library path for a file called libnamespec.a (namespec is what comes after -l).
For your example you should replace ${HSI_LIB} in target_link_libraries by :${HSI_LIB}.so.

OpenPose linking error on std::thread

So trying to build OpenPose from source, and was running into a linking problem. Current environment is Ubuntu 16.04.4. OpenCV version is 3.3.1. GCC version is 5.4.0.
[ 87%] Built target openpose
[ 87%] Linking CXX executable 1_extract_from_image.bin
[ 87%] Linking CXX executable openpose.bin
[ 87%] Linking CXX executable 3_user_input_processing_and_output.bin
[ 87%] Linking CXX executable 2_extract_pose_or_heatmat_from_image.bin
[ 87%] Linking CXX executable 1_custom_post_processing.bin
[ 87%] Linking CXX executable 2_user_processing_function.bin
[ 88%] Linking CXX executable 1_openpose_read_and_display.bin
/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/libopencv_objdetect.so.3.3.1: undefined reference to std::thread::_State::~_State()#GLIBCXX_3.4.22
/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/libopencv_objdetect.so.3.3.1: undefined reference to std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)())#GLIBCXX_3.4.22
/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/libopencv_objdetect.so.3.3.1: undefined reference to typeinfo for std::thread::_State#GLIBCXX_3.4.22
collect2: error: ld returned 1 exit status
examples/openpose/CMakeFiles/openpose.bin.dir/build.make:150: recipe for target 'examples/openpose/openpose.bin' failed
make[2]: *** [examples/openpose/openpose.bin] Error 1
CMakeFiles/Makefile2:1135: recipe for target 'examples/openpose/CMakeFiles/openpose.bin.dir/all' failed
make[1]: *** [examples/openpose/CMakeFiles/openpose.bin.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
I just had the same issue and installed the latest versions of gcc and g++, which solved the problem. Like here:
https://askubuntu.com/a/789417
I just installed version 8 (thus gcc-8 and g++-8). Then you have to call update-alternatives as described there.

How to run googletest in CLion?

I want to use Googletest in my CLion Project.
So here is what I did:
I copied my googletest folder into the lib folder of my project.
I changed my CMakeLists.txt files like described in that Video: https://youtu.be/8Up5eNZ0FLw
and created that simple test:
#include "gtest/gtest.h"
TEST(basic_check, test_eq){
EXPECT_EQ(1,0);
}
I tried to run the test by pressing Shift + Ctrl + F10 and I got the following error:
"F:\Programs\CLion 2016.3\bin\cmake\bin\cmake.exe" --build C:\Users\Christian\ClionProjects\Geldautomat\cmake-build-debug --target runBasicTests -- -j 4
[ 16%] Building CXX object Tests/lib/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj
In file included from C:/Users/Christian/ClionProjects/Geldautomat/Tests/lib/googletest/include/gtest/internal/gtest-internal.h:40:0,
from C:/Users/Christian/ClionProjects/Geldautomat/Tests/lib/googletest/include/gtest/gtest.h:58,
from C:\Users\Christian\ClionProjects\Geldautomat\Tests\lib\googletest\src\gtest-all.cc:39:
C:/Users/Christian/ClionProjects/Geldautomat/Tests/lib/googletest/include/gtest/internal/gtest-port.h: In function 'int testing::internal::posix::StrCaseCmp(const char*, const char*)':
C:/Users/Christian/ClionProjects/Geldautomat/Tests/lib/googletest/include/gtest/internal/gtest-port.h:2328:25: error: '_stricmp' was not declared in this scope
return _stricmp(s1, s2);
^
mingw32-make.exe[3]: *** [Tests/lib/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj] Error 1
mingw32-make.exe[2]: *** [Tests/lib/googletest/CMakeFiles/gtest.dir/all] Error 2
mingw32-make.exe[1]: *** [Tests/basic_tests/CMakeFiles/runBasicTests.dir/rule] Error 2
mingw32-make.exe: *** [runBasicTests] Error 2
Tests\lib\googletest\CMakeFiles\gtest.dir\build.make:62: recipe for target 'Tests/lib/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj' failed
CMakeFiles\Makefile2:162: recipe for target 'Tests/lib/googletest/CMakeFiles/gtest.dir/all' failed
CMakeFiles\Makefile2:267: recipe for target 'Tests/basic_tests/CMakeFiles/runBasicTests.dir/rule' failed
Makefile:200: recipe for target 'runBasicTests' failed
My CMakeLists.txt in this directory is:
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
add_executable(runBasicTests
basic_check.cpp)
target_link_libraries(runBasicTests gtest gtest_main)
target_link_libraries(runBasicTests src)
Where my Source Code can be found in directory src.
My main.cpp is in the root directory and my Basic Test is in Tests/basic_tests
Tried the same on my Linux Notebook with CLion. Got the Error:
/home/christian/Downloads/clion-2016.3/bin/cmake/bin/cmake --build /home/christian/ClionProjects/Geldautomat/cmake-build-debug --target runBasicTests -- -j 4
Scanning dependencies of target gtest
[ 16%] Building CXX object Tests/lib/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 33%] Linking CXX static library libgtest.a
[ 33%] Built target gtest
Scanning dependencies of target gtest_main
[ 50%] Building CXX object Tests/lib/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[ 66%] Linking CXX static library libgtest_main.a
[ 66%] Built target gtest_main
Scanning dependencies of target runBasicTests
[ 83%] Building CXX object Tests/basic_tests/CMakeFiles/runBasicTests.dir/basic_check.cpp.o
[100%] Linking CXX executable runBasicTests
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lsrc
collect2: error: ld returned 1 exit status
Tests/basic_tests/CMakeFiles/runBasicTests.dir/build.make:97: recipe for target 'Tests/basic_tests/runBasicTests' failed
gmake[3]: *** [Tests/basic_tests/runBasicTests] Error 1
CMakeFiles/Makefile2:256: recipe for target 'Tests/basic_tests/CMakeFiles/runBasicTests.dir/all' failed
gmake[2]: *** [Tests/basic_tests/CMakeFiles/runBasicTests.dir/all] Error 2
CMakeFiles/Makefile2:268: recipe for target 'Tests/basic_tests/CMakeFiles/runBasicTests.dir/rule' failed
gmake[1]: *** [Tests/basic_tests/CMakeFiles/runBasicTests.dir/rule] Error 2
Makefile:201: recipe for target 'runBasicTests' failed
gmake: *** [runBasicTests] Error 2
It would be fine if my Project runs on Linux..
Any suggestions?
-ChrizZ
You can follow this link ->
https://www.youtube.com/channel/UCvHU1FkIE-ogFTtXnKZsqWA
There are 2 videos. Both are helpful. I set up googleTest in my CLion yesterday following the 8:19 long video.