g++ (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2
I have a static library called sdpAPI.a
I am trying to link my cpp file to it using cmake.
My CMakeLists.txt looks like this?
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(demo_project CXX)
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CMAKE_C_FLAGS "-Wall -Wextra -Wunreachable-code -O0 -D_DEBUG -ggdb -m32")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
INCLUDE_DIRECTORIES(sdpapi)
LINK_DIRECTORIES(~/projects/test_sdp/sdpapi)
SET(source_files main.cpp)
SET(libs sdpAPI)
ADD_EXECUTABLE(demo ${source_files})
TARGET_LINK_LIBRARIES(demo ${libs})
And my sdpAPI.a is located in this directory test_sdp/sdpapi/sdpAPI.a
The error I am getting is the following:
[100%] Building CXX object CMakeFiles/demo.dir/main.cpp.o
Linking CXX executable demo
/usr/bin/ld: cannot find -lsdpAPI
collect2: ld returned 1 exit status
make[2]: *** [demo] Error 1
make[1]: *** [CMakeFiles/demo.dir/all] Error 2
make: *** [all] Error 2
Can anyone see anything obvious that I am doing wrong.
I should have renamed sdpAPI.a to libsdpAPI.a
This solved my problem. A silly mistake which cost me 3 hours.
Hope this helps someone else.
Additional advice for previous answer.
To understand what's going on with compilation/linking just run make with VERBOSE=1 option to see full command used by make.
And of course link options for gcc
Use $ENV{HOME} instead of ~.
Related
I'm trying to use cplexAPI C++ in a CLion project with C++11 on Windows 10. I have looked at several posts related to this question (e.g. config CMakeLists.txt, install MinG64) and I have managed to configure my CMakeLists.txt in the following way:
cmake_minimum_required(VERSION 3.15)
project(VRP_PRP)
add_executable(VRP_PRP main.cpp held-karp.h held-karp.cpp)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -O -fPIC -fexceptions -DNDEBUG -DIL_STD -std=c++11")
include_directories(/biblio/cplex/include/)
include_directories(/biblio/cplex/include/ilcplex)
include_directories(/biblio/concert/include)
include_directories(/biblio/concert/include/ilconcert)
target_link_libraries(VRP_PRP PUBLIC /biblio/cplex/lib/x64_windows_msvc14/stat_mda/cplex12100.lib)
target_link_libraries(VRP_PRP PUBLIC /biblio/cplex/lib/x64_windows_msvc14/stat_mda/ilocplex.lib)
target_link_libraries(VRP_PRP PUBLIC /biblio/concert/lib/x64_windows_msvc14/stat_mda/concert.lib)
target_link_libraries(VRP_PRP PUBLIC "-lilocplex -lconcert -lcplex -lm -lpthread")
it happens that when building my project it throws the following errors:
[ 33%] Linking CXX executable VRP_PRP.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 -lilocplex
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 -lconcert
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 -lcplex
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [CMakeFiles\VRP_PRP.dir\build.make:105: VRP_PRP.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:75: CMakeFiles/VRP_PRP.dir/all] Error 2
mingw32-make.exe: *** [Makefile:83: all] Error 2
and by including the libraries (#include <ilcplex/ilocplex.h>) in my main.cpp it can't find them.
I have tried using 2 ways to link libraries in my CMakeLists.txt:
a) #set (target_link_options "-lilocplex -lconcert -lcplex -lm -lpthread -framework CoreFoundation -framework IOKit -std=c++11")
b) #target_link_libraries(VRP_PRP PUBLIC "-lilocplex -lconcert -lcplex -lm -lpthread")
Any help or idea will be appreciated.
Thanks.
My solution.
I installed Visual Studio 2017 Community together with CPLEX 12.9 Academic Version, then I opened the examples which is in:
C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\examples
and they already come with the configuration done.
Recently I have acquired the "curses.h" and built the PDCurses "pdcurses.a" library file thanks to:
https://github.com/Alexpux/MINGW-packages/tree/master/mingw-w64-pdcurses
package. I also have prepared cmake files:
# pdcurses-config.cmake
set(PDCURSES_LIBDIR "${PROJECT_SOURCE_DIR}/lib")
set(PDCURSES_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src/include")
set(PDCURSES_LIBRARIES "-L${PDCURSES_LIBDIR} -lpdcurses -static -Wall -Werror")
string(STRIP "${PDCURSES_LIBRARIES}" PDCURSES_LIBRARIES)
# CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(MatrixAlgebra)
set(CMAKE_CXX_STANDARD 11)
set(PDCURSES_DIR "${PROJECT_SOURCE_DIR}/cmake")
find_package(PDCURSES REQUIRED)
include_directories(${PDCURSES_INCLUDE_DIRS})
set(SOURCE_FILES src/main.cpp)
add_executable(MatrixAlgebra ${SOURCE_FILES})
target_link_libraries(MatrixAlgebra ${PDCURSES_LIBRARIES})
Unfortunately I'm unable to link a simple "Hello World!" console program because either I am getting this:
mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lpdcurses
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: * [CMakeFiles\MatrixAlgebra.dir\build.make:97: MatrixAlgebra.exe] Error 1
mingw32-make.exe[2]: [CMakeFiles\Makefile2:67: CMakeFiles/MatrixAlgebra.dir/all] Error 2
mingw32-make.exe[1]: [CMakeFiles\Makefile2:79: CMakeFiles/MatrixAlgebra.dir/rule] Error 2
mingw32-make.exe: * [Makefile:117: MatrixAlgebra] Error 2
or this (when I change "pdcurses.a" to "libpdcurses.a"):
Process finished with exit code -1073741515 (0xC0000135)
I simply don't know what to do to make it proceed without problems.
you shouldn't treat target_link_libraries() like commandline to feed it with parameters like -Wall
I don't know pdcurses, but when find_package finds that lib you should probably use something like:
target_link_libraries(MatrixAlgebra pdcurses::pdcurses)
I've been working on a project in CLion for quite some time now (over a month). All of a sudden, CLion will not build all of my files... When I run my program, my messages build looks like this:
Scanning dependencies of target main.cpp
[ 11%] Building CXX object CMakeFiles/main.cpp.dir/Custom_Types.cpp.o
[ 22%] Linking CXX executable ../bin/main.cpp
ld: library not found for -l*.cpp
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
make[3]: *** [../bin/main.cpp] Error 1
make[2]: *** [CMakeFiles/main.cpp.dir/all] Error 2
make[1]: *** [CMakeFiles/main.cpp.dir/rule] Error 2
make: *** [main.cpp] Error 2
Great... what the flippin fireworks is going on? This is what my CMake looks like...
cmake_minimum_required(VERSION 3.7)
project(Crazy_Sniper)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fpermissive")
find_package (OpenGL REQUIRED)
find_package (GLUT REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR} ${GLUT_INCLUDE_DIRS})
file(GLOB SOURCE_FILES
*.cpp
*.h
)
add_executable(main.cpp ${SOURCE_FILES} Custom_Types.cpp)
target_link_libraries (main.cpp ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES}
mdl pthread)
Does anyone know what the problem is? I've looked through countless forums, and I cannot seem to find someone with a similar problem. Any help would be much appreciated.
Update! I've managed to get CLion to build my files, but main still does nothing... I try simply printing something out, and the console does nothing. I get an error code 11 for some reason...?
Thank you!
I am trying to build a cmakelist file from makefile of leap motion, I can compile in a specific directory, I need to copy /include/ and /lib/x64/ directories . The makefile is the follow:
LEAP_LIBRARY := ./lib/x64/libLeap.so -Wl,-rpath,./lib/x64
Sample: Sample.cpp
$(CXX) -Wall -g -I include Sample.cpp -o Sample $(LEAP_LIBRARY)
I have tried to build a cmakelist file as follows:
cmake_minimum_required(VERSION 2.8)
project(Sample)
INCLUDE_DIRECTORIES(/include/)
LINK_DIRECTORIES(/lib/x64/)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -I /include/ -Wl,-rpath,./lib/x64")
add_executable(Sample Sample.cpp )
target_link_libraries(Sample libLeap.so)
But I always get the same error:
Linking CXX executable Sample
/usr/bin/ld: can't find -lLeap
collect2: error: ld returned 1 exit status
make[2]: *** [Sample] Error 1
make[1]: *** [CMakeFiles/Sample.dir/all] Error 2
make: *** [all] Error 2
Thanks and regards.
I could solve with following lines:
cmake_minimum_required(VERSION 2.8)
project(Sample)
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
INCLUDE_DIRECTORIES(../include/)
LINK_DIRECTORIES(../lib/x64/)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g")
add_executable(Sample Sample.cpp )
target_link_libraries(Sample -lLeap)
This solution has warnings but works:
CMake Warning (dev) at CMakeLists.txt:5 (LINK_DIRECTORIES):
This command specifies the relative path
../lib/x64
as a link directory.
Policy CMP0015 is not set: link_directories() treats paths relative to the
source dir. Run "cmake --help-policy CMP0015" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring done
-- Generating done
-- Build files....
Two way to delete this warning:
cmake_minimum_required(VERSION 2.8)
project(Sample)
cmake_policy(SET CMP0015 NEW)
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
INCLUDE_DIRECTORIES(../include/)
LINK_DIRECTORIES(lib/x64/)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g")
add_executable(Sample Sample.cpp )
target_link_libraries(Sample -lLeap)
Or use cmake .. -Wno-dev
I'm trying to compile a program that uses the URG (Laser scanner) library along with PCL. URG uses make to build but PCL uses cmake. I've been trying to use cmake for both but i've been having issues.
I found FindURG.cmake and put it in the modules folder here: https://github.com/wicron/vlidar/blob/master/cmake/FindURG.cmake
My CMakeLists is:
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(MY_GRAND_PROJECT)
find_package(PCL 1.3 REQUIRED COMPONENTS common io)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
find_package(URG REQUIRED)
include_directories(${URG_INCLUDE_DIR})
link_directories(${URG_LIBRARY})
#add_executable(pcd_write_test pcd_write.cpp)
add_executable(urg_read_test gdScanSample.cpp)
#target_link_libraries(pcd_write_test ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES})
target_link_libraries(urg_read_test ${URG_LIBRARY})
SET(CMAKE_C_FLAGS "-I/usr/local/include/urg")
#SET(CMAKE_CXX_FLAGS "-I/usr/local/include/urg")
PCL is found fine, URG is also found as shown below. The directories look fine too.
root#CCSL02:/home/marwan/pcl_sample# cmake CMakeLists.txt
-- looking for PCL_COMMON
-- looking for PCL_OCTREE
-- looking for PCL_IO
-- Found c_urg libraries. /usr/local/lib/libc_urg_system.so/usr/local/lib/libc_urg.so/usr/local/lib/libc_urg_connection.so/usr/lib/liburg.so/usr/lib/liburg_connection.so/usr/lib/liburg_system.so/usr/lib/liburg_common.so/usr/lib/liburg_coordinate.so/usr/lib/liburg_geometry.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/marwan/pcl_sample
But as soon as I run make, here's what I get:
root#CCSL02:/home/marwan/pcl_sample# make
[100%] Building CXX object CMakeFiles/urg_read_test.dir/gdScanSample.cpp.o
/home/marwan/pcl_sample/gdScanSample.cpp:10:21: fatal error: UrgCtrl.h: No such file or directory compilation terminated.
make[2]: *** [CMakeFiles/urg_read_test.dir/gdScanSample.cpp.o] Error 1
make[1]: *** [CMakeFiles/urg_read_test.dir/all] Error 2
make: *** [all] Error 2
I've tried to play with the CMakeLists in which I tried added the CXX flags but no luck
It should be noted that the following makefile compiles the urg program normally
# Makefile for urg_sample
# Satofumi KAMIMURA
# $Id: Makefile 1997 2012-10-30 02:57:51Z satofumi $
CXXFLAGS = -g -O0 -Wall -Werror `urg-config --cflags` `sdl-config --cflags`
LDFLAGS =
LDLIBS = `urg-config --libs` `sdl-config --libs` -lc
TARGET = gdScanSample
all : $(TARGET)
clean :
$(RM) *.o $(TARGET)
.PHONY : all clean
You need to verify that SET(CMAKE_C_FLAGS "-I/usr/local/include/urg") points to the directory where all the h files are. Maybe you will need to add more than one location.
Solved thanks to ComicSansMS
Here's a working CMakeLists.txt:
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(MY_GRAND_PROJECT)
find_package(PCL 1.3 REQUIRED)#COMPONENTS common io)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
find_package(URG REQUIRED)
include_directories(${URG_INCLUDE_DIR}/urg)
link_directories(${URG_LIBRARIES})
add_executable(pcd_write_test pcd_write.cpp)
target_link_libraries(pcd_write_test ${PCL_LIBRARIES} ${URG_LIBRARIES})