I get the following error when compiling my program c++ with tesseract and opencv:
make
[ 50%] Linking CXX executable car_license_plates
ld: library not found for -llept
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [car_license_plates] Error 1
make[1]: *** [CMakeFiles/car_license_plates.dir/all] Error 2
make: *** [all] Error 2
My system is: MacOS X Darwin - 15.4.0 - x86_64
The CMakeLists.txt is the follow:
cmake_minimum_required(VERSION 2.8)
set(CMAKE_BUILD_TYPE Release)
project( car_license_plates )
set(CMAKE_CXX_FLAGS "-Wall -O2 -std=c++0x ")
add_executable( ${PROJECT_NAME} car_license_plates.cpp )
# find opencv package
find_package( OpenCV REQUIRED )
# includes
set(LEPTONICA_INCLUDE_PATH "/usr/local/Cellar/leptonica/1.73/include/leptonica")
set(TESSERACT_INCLUDE_PATH "/usr/local/Cellar/tesseract/3.04.01_2/include/tesseract")
include_directories(${OpenCV_INCLUDE_DIRS} ${LEPTONICA_INCLUDE_PATH} ${TESSERACT_INCLUDE_PATH})
# libraries
set(LEPTONICA_LIBS "lept")
set(TESSERAC_LIBS "tesseract")
set(LIBS ${LIBS} ${OpenCV_LIBS} ${LEPTONICA_LIBS} ${TESSERAC_LIBS})
target_link_libraries(${PROJECT_NAME} ${LIBS})
where are the mistake?
Related
I use c++ project with opencv and dlib libraries. I have CMakeLists.txt:
cmake_minimum_required(VERSION 3.20.0)
project(project1)
find_package(OpenCV REQUIRED)
include(FetchContent)
FetchContent_Declare(dlib
GIT_REPOSITORY https://github.com/davisking/dlib.git
GIT_TAG v19.18
)
FetchContent_MakeAvailable(dlib)
add_executable(project1 main.cpp)
target_link_libraries(project1 ${OpenCV_LIBS} dlib::dlib)
target_compile_options(project1 PUBLIC "$<$<CONFIG:RELEASE>:${MY_RELEASE_OPTIONS}>")
I write in cygwin cmake .. -G "Unix Makefiles". I use "Unix Makefiles" to create makefile that use to command "make". After this I write make, but as a result I get error:
collect2: error: ld execution ended with return code 1
make[2]: *** [CMakeFiles/project1.dir/build.make:123: project1.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:115: CMakeFiles/project1.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
What I need to do to fix this problem?
I am currently trying to install the SDL library with C++ and Clion. I watched many youtube videos and googled the errors but still cannot find a way to fix this error.
"C:\Program Files\JetBrains\CLion 2021.1.2\bin\cmake\win\bin\cmake.exe" --build D:\Programing\C++\School\HackClub\Day2\cmake-build-debug --target Day2 -- -j 6
[ 50%] Linking CXX executable Day2.exe
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2main
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\Day2.dir\build.make:95: Day2.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:82: CMakeFiles/Day2.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:89: CMakeFiles/Day2.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:123: Day2] Error
Here is my CMAKE file.
project(Day2)
set(CMAKE_CXX_STANDARD 14)
set(SDL2_INCLUDE_DIR D:\\Programing\\C++\\libs\\SDL\\include)
set(SDL2_LIBRARY D:\\Programing\\C++\\libs\\SDL\\lib\\x86)
include_directories(${SDL2_INCLUDE_DIR})
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARY})
target_link_libraries(${PROJECT_NAME} SDL2main SDL2)
I tried to test OpenMP on MacOS with the Apple Clang compiler that comes with Xcode.
Code:
#include <iostream>
#include <cmath>
#include </usr/local/opt/libomp/include/omp.h>
int main() {
std::cout << "Hello, World!" << std::endl;
#pragma omp parallel
{
printf("Hello World! \n");
}
return 0;
}
and this is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.19)
project(untitled)
set(CMAKE_CXX_STANDARD 14)
include (FindOpenMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
message (VERBOSE "OpenML library found")
else()
message (FATAL_ERROR "OpenML library not found (required for multithreading)")
endif ()
add_executable(untitled main.cpp)
This is the compiler's error:
Scanning dependencies of target untitled
[ 50%] Building CXX object CMakeFiles/untitled.dir/main.cpp.o
[100%] Linking CXX executable untitled
Undefined symbols for architecture x86_64:
"___kmpc_fork_call", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [untitled] Error 1
make[2]: *** [CMakeFiles/untitled.dir/all] Error 2
make[1]: *** [CMakeFiles/untitled.dir/rule] Error 2
make: *** [untitled] Error 2
The OpenMP is installed using hombrew libomp I also tried adding environment variable LDFLAGS=-L/usr/local/opt/libomp/lib/ and it does not affect the result
UPDATE: COMPILATION WITH VERBOSE=1:
...
[100%] Linking CXX executable untitled
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -E cmake_link_script CMakeFiles/untitled.dir/link.txt --verbose=1
/Library/Developer/CommandLineTools/usr/bin/c++ -Xclang -fopenmp -g -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names -L/usr/local/opt/libomp/lib/ CMakeFiles/untitled.dir/main.cpp.o -o untitled
Undefined symbols for architecture x86_64:
"___kmpc_fork_call", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [untitled] Error 1
make[2]: *** [CMakeFiles/untitled.dir/all] Error 2
make[1]: *** [CMakeFiles/untitled.dir/rule] Error 2
make: *** [untitled] Error 2
By using set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") and using set in other places, you are replacing the flags that CMAKE puts. It is better to append in this case rather than replace. You can use add_compile_options(-Wall) here.
As mentioned by #Tsyvarev, it is perhaps better to use imported library. Here are a few other ways you can use target_link_libraries.
For your particular case, it is best to replace
find_package(OpenMP REQUIRED)
where you currently have include (FindOpenMP). Further, remove the if condition as well. Finally, add the following to the end of your CMakeLists.txt file.
target_link_libraries(
untitled
PRIVATE
OpenMP::OpenMP_CXX
)
Here is a good explanation of the difference between PRIVATE and PUBLIC.
Your final CMakeLists.txt file should look like:
cmake_minimum_required(VERSION 3.19)
project(untitled)
set(CMAKE_CXX_STANDARD 14)
find_package(OpenMP REQUIRED)
add_executable(
untitled
main.cpp
)
target_link_libraries(
untitled
PRIVATE
OpenMP::OpenMP_CXX
)
Thanks to Tsyvarev, for helping me with CMake a few months ago. Further, thanks to the answers that Tsyvarev points toward, which my answer is based on (along with my own testing).
I'm trying to include the GMP library into my project.
This is my folder tree:
As you can see, the gmp folder (that contains include and lib) is into the include folder.
This is my app/CMakeLists.txt:
cmake_minimum_required(VERSION 3.18)
add_executable(
${PROJECT_NAME}
../include/KMC/kmc_api/kmc_file.cpp
../include/KMC/kmc_api/kmer_api.cpp
../include/KMC/kmc_api/mmer.cpp
main.cpp
)
include_directories(
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/src
)
target_link_directories(${PROJECT_NAME} PUBLIC
${CMAKE_SOURCE_DIR}/include/gmp/lib
)
target_link_libraries(${PROJECT_NAME} PUBLIC
gmp
gmpxx
)
target_include_directories(${PROJECT_NAME} PUBLIC
${CMAKE_SOURCE_DIR}/include/gmp/include
)
target_compile_definitions(${PROJECT_NAME} PRIVATE DEBUG=1)
and this, is the CMakeLists.txt in the project root:
cmake_minimum_required(VERSION 3.18)
set(CMAKE_CXX_COMPILER "/usr/local/bin/g++")
project(MyProj)
enable_language(CXX)
set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 1)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -pedantic-errors -fopenmp")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_VERBOSE_MAKEFILE ON)
include(CMakeToolsHelpers OPTIONAL)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include_directories(include)
include_directories(include/KMC)
add_subdirectory(app)
After, cd build && cmake .. I run make -j12 and than, -the compilation fail:
[100%] Linking CXX executable DynaDBG
cd /Users/th3g3ntl3man/Desktop/Repository/DynaDBG/build/app && /usr/local/Cellar/cmake/3.18.4/bin/cmake -E cmake_link_script CMakeFiles/DynaDBG.dir/link.txt --verbose=1
/usr/local/bin/g++ -Wall -Wextra -Wpedantic -pedantic-errors -fopenmp -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/DynaDBG.dir/__/include/KMC/kmc_api/kmc_file.cpp.o CMakeFiles/DynaDBG.dir/__/include/KMC/kmc_api/kmer_api.cpp.o CMakeFiles/DynaDBG.dir/__/include/KMC/kmc_api/mmer.cpp.o CMakeFiles/DynaDBG.dir/main.cpp.o -o DynaDBG -L/Users/th3g3ntl3man/Desktop/Repository/DynaDBG/include/gmp/lib -Wl,-rpath,/Users/th3g3ntl3man/Desktop/Repository/DynaDBG/include/gmp/lib -lgmp -lgmpxx
Undefined symbols for architecture x86_64:
"__ZlsRSoPK12__mpz_struct", referenced from:
__ZlsIA1_12__mpz_structS1_ERSoS2_RK10__gmp_exprIT_T0_E in main.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [app/CMakeFiles/DynaDBG.dir/build.make:151: app/DynaDBG] Error 1
make[2]: Leaving directory '/Users/th3g3ntl3man/Desktop/Repository/DynaDBG/build'
make[1]: *** [CMakeFiles/Makefile2:116: app/CMakeFiles/DynaDBG.dir/all] Error 2
make[1]: Leaving directory '/Users/th3g3ntl3man/Desktop/Repository/DynaDBG/build'
make: *** [Makefile:106: all] Error 2
UPDATE:
Compiling the example I have this error:
I'm trying to link my project with google C++ testing framework. I use Mac OS X El Capitan and I have installed test library in the default path.
lib:
/usr/local/lib/libgtest_main.a
/usr/local/lib/libgtest.a
include (for headers):
/usr/local/include/gtest
I created a new CLion (2016.1.1) project a this is the CMakeList.txt which should include the lib.
cmake_minimum_required(VERSION 3.5)
project(GoogleTest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(GoogleTest ${SOURCE_FILES})
target_link_libraries(GoogleTest gtest gtest_main)
This is the result:
Scanning dependencies of target GoogleTest
[ 50%] Building CXX object CMakeFiles/GoogleTest.dir/main.cpp.o
[100%] Linking CXX executable GoogleTest
ld: library not found for -lgtest
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [GoogleTest] Error 1
make[1]: *** [CMakeFiles/GoogleTest.dir/all] Error 2
make: *** [all] Error 2
How can I fix this? Thanks in advance
It looks like /usr/local/lib is not in the compiler's library path list. Try specifying the full path for the libraries in target_link_libraries.
target_link_libraries(GoogleTest /usr/local/lib/libgtest.a /usr/local/lib/libgtest_main.a)