Hi, as will be apparent I am new to using CMake. I’m using CLion in Windows with the visual studio 2019 toolchain, and I’m trying to import a library to use and I’m having trouble.
The library is copied to the top of the project, in the folder next to main. The project structure looks like this:
CMakeLists.txt
main.cpp
testClass/testClass.h
testClass/testClass.cpp
libName/DLL/THE_LIB.dll
libName/Lib/THE_LIB.lib
libName/Include/THE_LIB.h
libName/Include/VariousOthers1.h
libName/Include/VariousOthers2.h
The Cmake file looks like this:
cmake_minimum_required(VERSION 3.30)
project(untitled)
set(CMAKE_CXX_STANDARD 20)
add_executable(untitled main.cpp
testClass/testClass.cpp
testClass/testClass.h)
target_link_libraries(untitled C:/path/to/lib/libName/Lib/THE_LIB.lib)
main:
#include "testClass/testClass.h"
#include "libName/Include/THE_LIB.h"
#include "libName/Include/VariousOthers1.h"
#include "libName/Include/VariousOthers2.h"
int main() {
libNameClass instance = libNameClass();
testClass greeter = testClass();
greeter.greet();
return 0;
}
If I comment out the libNameClass and the #includes relating to it, it works fine (testClass prints hello world). If I leave them in, I get an error and a warning:
“error LNK2019: unresolved external symbol” relating to the libNameClass
“warning LNK4272: library machine type ‘x86’ conflicts with target machine type ‘x64’”
Have I made an error with my CMake file, or is the error due to the warning, and is there an obvious way to get around the warning? I would have thought 64 bit machines oculd run 32 bit libraries (and I’m not sure why this warning is coming up, as the library is relatively recent).
Thanks