0

I have recently started using CMake as a build tool and I am pretty new to it. I have a .lib file I am trying to link to my project, however, I am having issues with compiling.

My CMakeList file. main.cpp and File structure are the following:


# set the project name
project(PS5Bluetooth)

# add_subdirectory(DualSenseWindows_V0.1)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
include_directories(${CMAKE_SOURCE_DIR}/include)
link_directories(${CMAKE_SOURCE_DIR}/libs)

add_library(ds5w_x64 STATIC IMPORTED GLOBAL)

# add the executable
add_executable(${PROJECT_NAME} main.cpp)

# target_include_directories(${PROJECT_NAME} PRIVATE "includes")
target_link_libraries(${PROJECT_NAME} PRIVATE ds5w_x64.lib)

#include <iostream>
#include "ds5w.h"


int main(void)
{
    std::cout << "Hello world!\n";

    // Array of controller infos
    DS5W::DeviceEnumInfo infos[16];
    
    // Number of controllers found
    unsigned int controllersCount = 0;
    
    // Call enumerate function and switch on return value
    DS5W::enumDevices(infos, 16, &controllersCount);
}

File structure

When compiling, the error I am seeing is the following:

PS C:\Users\cayod\OneDrive\Documents\Repos\Bluetooth_PS5\Code\PS5-Controller-Bluetooth\build> make
Consolidate compiler generated dependencies of target PS5Bluetooth
[ 50%] Linking CXX executable PS5Bluetooth.exe
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/PS5Bluetooth.dir/objects.a(main.cpp.obj):C:/Users/cayod/OneDrive/Documents/Repos/Bluetooth_PS5/Code/PS5-Controller-Bluetooth/main.cpp:16: undefined reference to `__imp__ZN4DS5W11enumDevicesEPvjPjb'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/PS5Bluetooth.dir/build.make:101: PS5Bluetooth.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/PS5Bluetooth.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Again, I am new to cmake and so any help would be appreciated. Thank you.

  • `ds5w_x64.lib` does not seem to be built for mingw. You should use DS5W built exactly with the same compiler that you use. – 273K Oct 16 '22 at 22:19

0 Answers0