开发者

cmake cannot find static library

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 ~.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜