这是我项目结构的相关部分
iNode
├── CMakeLists.txt
├── src
| └──iNode.c
├── include
| └──iNode.h
└── test
└──tests.cpp
cmake无法从iNode.c中找到函数定义 我不知道为什么当我add_library时他们没有被添加 我已经尝试了几种链接库的排列
cmake_minimum_required (VERSION 2.8)
project(iNode)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -Wshadow -Wpedantic -D_XOPEN_SOURCE=700")
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wextra -Wshadow -Werror -g -D_XOPEN_SOURCE=700")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g")
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()
include_directories(${f16fs_INCLUDE_DIRS} ${dyn_array_INCLUDE_DIRS} include)
add_library(${PROJECT_NAME} SHARED src/${PROJECT_NAME}.c)
set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
install(TARGETS ${PROJECT_NAME} DESTINATION lib)
install(FILES include/${PROJECT_NAME}.h DESTINATION include)
add_executable(${PROJECT_NAME}_test test/tests.cpp)
target_link_libraries(${PROJECT_NAME}_test gtest pthread ${PROJECT_NAME})
set(${PROJECT_NAME}_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include CACHE INTERNAL "${PROJECT_NAME}: Include Directories" FORCE)
错误
$ make
-- Configuring done
-- Generating done
-- Build files have been written to: /home/syg84/project3_syg84/build
[ 10%] Built target dyn_array_tester
[ 20%] Built target dyn_array
[ 30%] Built target bitmap_tester
[ 40%] Built target bitmap
[ 50%] Built target block_store
[ 60%] Built target block_store_test
[ 70%] Built target iNode
[ 80%] Built target f16fs
[ 90%] Built target f16fs_test
Scanning dependencies of target iNode_test
[ 95%] Linking CXX executable iNode_test
CMakeFiles/iNode_test.dir/test/tests.cpp.o: In function `getDirectoryContents_rootDirectory_Test::TestBody()':
/home/syg84/project3_syg84/iNode/test/tests.cpp:6: undefined reference to `createNewINodeArray(unsigned long)'
/home/syg84/project3_syg84/iNode/test/tests.cpp:8: undefined reference to `getDirectoryContents(iNode**, unsigned char)'
/home/syg84/project3_syg84/iNode/test/tests.cpp:10: undefined reference to `destroyINodeArray(iNode**, unsigned long)'
collect2: error: ld returned 1 exit status
make[2]: *** [iNode/iNode_test] Error 1
make[1]: *** [iNode/CMakeFiles/iNode_test.dir/all] Error 2
make: *** [all] Error 2