binbin binbin - 3 years ago 100
C++ Question

C++: static link not found

I make a libtest_lib.a file with cmake.

cmake_minimum_required(VERSION 3.8)
project(test)
set(CMAKE_CXX_STANDARD 98)
set(SOURCE_FILES library.cpp library.h)
add_library(test_lib ${SOURCE_FILES})


then in my executable C++ project ,I include the
#include "library.h"

and the CMakeList.txt:

cmake_minimum_required(VERSION 3.8)
project(study)
set(CMAKE_CXX_STANDARD 98)
set(SOURCE_FILES main.cpp)
add_executable(study ${SOURCE_FILES})
target_link_libraries(study libtest_lib.a) //libtest_lib.a file under the project path


but it fails.

/Users/bin381/CLionProjects/study/main.cpp:1:10: fatal error: 'library.h' file not found

Answer Source

Please add the include directories as mentioned in the documentation : https://cmake.org/cmake/help/v3.0/command/include_directories.html Otherwise cmake will not be able to find where to look in for include files.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download