I have a simple C library that have following files: /testlib/library.h /testlib/library.lib
library.h contains:
#ifdef __cplusplus
extern "C" {
#endif
void function(int a, int b);
#ifdef __cplusplus
}
#endif
I'm trying to use this header in my main.cpp:
extern "C" {
#include "library.h"
}
int main()
{
function(1, 2);
return 0;
}
And here is my CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(StudyProject)
include_directories(testlib/)
link_directories(testlib/)
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/testlib/)
I use Qt Creator (Windows platform, MinGW 7.3.0) and it builds project with following command:
cmake.exe --build . --target all
But i'm getting following error while linking:
undefined reference to 'function'
Can anyone help me what am I doing wrong?