Reputation: 2097
I am working on trying to get a cross compile setup for making windows applications using ubuntu as a development platform.
I have WxWidgets working with help of a previous post. I am now trying to get libCURL working. I need to get CMAKE to find the linker options for CURL.
I CAN cross compile simple CURL code using: ~/mxe/usr/bin/x86_64-w64-mingw32.static-g++ -DCURL_STATICLIB main.cpp -o winmain $(~/mxe/usr/bin/x86_64-w64-mingw32.static-curl-config --cflags) $(~/mxe/usr/bin/x86_64-w64-mingw32.static-curl-config --libs)
This is great! I can compile a single file! But, now how to do this with CMAKE?
I have attempted this:
cmake_minimum_required(VERSION 3.11)
SET (PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
SET(PROJECT_NAME "WxWidgets")
SET(CMAKE_C_COMPILER x86_64-w64-mingw32.static)
SET(CMAKE_CXX_COMPILER x86_64-w64-mingw32.static-g++)
project(
${PROJECT_NAME}
VERSION 1.0)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lstdc++ -static")
file(GLOB all_SRCS
"${PROJECT_SOURCE_DIR}/src/*.h"
"${PROJECT_SOURCE_DIR}/src/*.hpp"
"${PROJECT_SOURCE_DIR}/src/*.c"
"${PROJECT_SOURCE_DIR}/src/*.cpp"
"${PROJECT_SOURCE_DIR}/src/**/*.c"
"${PROJECT_SOURCE_DIR}/src/**/*.cpp"
"${PROJECT_SOURCE_DIR}/src/**/*.hpp"
)
add_executable(${PROJECT_NAME} ${all_SRCS})
set(CMAKE_C_FLAGS "~/mxe/usr/bin/x86_64-w64-mingw32.static-curl-config")
include( "${wxWidgets_USE_FILE}" )
find_package(wxWidgets REQUIRED)
target_include_directories(${PROJECT_NAME} PUBLIC ~/mxe/usr/i686-w64-mingw32.static/lib/ /home/kevin/mxe/usr/i686-w64-mingw32.static/include/wx-3.1/ /home/kevin/mxe/usr/i686-w64-mingw32.static/lib/wx/include/i686-w64-mingw32.static-msw-unicode-static-3.1/)
target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES} ~/mxe/usr/bin/x86_64-w64-mingw32.static-curl-config)
However, still get the linker errors:
[ 25%] Linking CXX executable WxWidgets.exe
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x541): undefined reference to `_imp__curl_global_init'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x547): undefined reference to `_imp__curl_easy_init'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x551): undefined reference to `_imp__curl_easy_setopt'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x593): undefined reference to `_imp__curl_easy_perform'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x5ae): undefined reference to `_imp__curl_easy_cleanup'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x5bb): undefined reference to `_imp__curl_global_cleanup'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x635): undefined reference to `_imp__curl_easy_strerror'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/WxWidgets.dir/build.make:141: WxWidgets.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/WxWidgets.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
kevin@kevin-CF-33S-1:~/source/repos/cpp/aiCamCPPClientApp/build$ make
[ 25%] Linking CXX executable WxWidgets.exe
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x541): undefined reference to `_imp__curl_global_init'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x547): undefined reference to `_imp__curl_easy_init'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x551): undefined reference to `_imp__curl_easy_setopt'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x593): undefined reference to `_imp__curl_easy_perform'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x5ae): undefined reference to `_imp__curl_easy_cleanup'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x5bb): undefined reference to `_imp__curl_global_cleanup'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x635): undefined reference to `_imp__curl_easy_strerror'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/WxWidgets.dir/build.make:141: WxWidgets.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/WxWidgets.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
And here another attempt (possibly closer?):
cmake_minimum_required(VERSION 3.11)
SET (PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
SET(PROJECT_NAME "WxWidgets")
SET(CMAKE_C_COMPILER i686-w64-mingw32.static)
SET(CMAKE_CXX_COMPILER i686-w64-mingw32.static-g++)
project(
${PROJECT_NAME}
VERSION 1.0)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lstdc++ -DCURL_STATICLIB -static")
file(GLOB all_SRCS
"${PROJECT_SOURCE_DIR}/src/*.h"
"${PROJECT_SOURCE_DIR}/src/*.hpp"
"${PROJECT_SOURCE_DIR}/src/*.c"
"${PROJECT_SOURCE_DIR}/src/*.cpp"
"${PROJECT_SOURCE_DIR}/src/**/*.c"
"${PROJECT_SOURCE_DIR}/src/**/*.cpp"
"${PROJECT_SOURCE_DIR}/src/**/*.hpp"
)
add_executable(${PROJECT_NAME} ${all_SRCS})
include( "${wxWidgets_USE_FILE}" )
find_package(wxWidgets REQUIRED)
find_package(CURL REQUIRED)
include_directories("~/mxe/usr/i686-w64-mingw32.static/lib/")
target_include_directories(${PROJECT_NAME} PUBLIC ~/mxe/usr/i686-w64-mingw32.static/lib/ /home/kevin/mxe/usr/i686-w64-mingw32.static/include/wx-3.1/ /home/kevin/mxe/usr/i686-w64-mingw32.static/lib/wx/include/i686-w64-mingw32.static-msw-unicode-static-3.1/)
target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES})
this results in a smaller error set:
[ 25%] Building CXX object CMakeFiles/WxWidgets.dir/src/GUIFrame.cpp.obj
[ 50%] Building CXX object CMakeFiles/WxWidgets.dir/src/aiCamClientAppApp.cpp.obj
[ 75%] Building CXX object CMakeFiles/WxWidgets.dir/src/aiCamClientAppMain.cpp.obj
[100%] Linking CXX executable WxWidgets.exe
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x540): undefined reference to `curl_global_init'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x545): undefined reference to `curl_easy_init'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x564): undefined reference to `curl_easy_setopt'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x57f): undefined reference to `curl_easy_setopt'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x58a): undefined reference to `curl_easy_perform'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x5a4): undefined reference to `curl_easy_cleanup'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x5b0): undefined reference to `curl_global_cleanup'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x624): undefined reference to `curl_easy_strerror'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/WxWidgets.dir/build.make:141: WxWidgets.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/WxWidgets.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
I am now wondering if my problems stem from hardcoding my directories, and if my paths aren't correctly setup and this may be causing issues with CMAKE being able to resolve the files for linking?
If anyone has any ideas about how to implement this in CMAKE correctly, it would greatly appreciate the help!
Thanks you very much! -Kevin
Upvotes: 0
Views: 330