Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake cannot find static library

Tags:

c++

cmake

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.

like image 408
ant2009 Avatar asked Jul 04 '11 07:07

ant2009


1 Answers

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.

like image 148
ant2009 Avatar answered Sep 24 '22 00:09

ant2009