0

I am currently new to C++ and CMake and I am trying to get the code for a project to build natively on windows 10: https://github.com/Marius-Juston/CarND-Path-Planning-Project . This is part of a Udacity Nanodegree and it contains starting scripts such as the main.cpp which is dependant on uWebSockets, checkout e94b6e1, in order to communicate with a Unity App. This in itself is dependant on OpenSSL, ZLib, and XMRigs-deps. They have install/setup files for Linux and mac but not for windows.

I have downloaded each of the source files uWebsockets (in my source directory), OpenSSL-Win64 (in Program Files), xmrig-deps-4.1 (in Program Files) and zlib-1.2.11 (in Program Files, this does not include a include and lib folder), and included the directories in my CMakeList.txt; however, I am getting:

C:/PROGRA~1/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lzlib-1.2.11
C:/PROGRA~1/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lOpenSSL-Win64
C:/PROGRA~1/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lxmrig-deps-4.1
C:/PROGRA~1/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -luWebSockets
collect2.exe: error: ld returned 1 exit status

From the documentation it seems that the libraries need to contain a *.a or *.so; however, none of the source files contain that. When I try to exclude these libraries from CMakeList I get this error:

CMakeFiles\path_planning.dir/objects.a(main.cpp.obj): In function `operator()':
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:113: undefined reference to `uWS::WebSocket<true>::send(char const*, unsigned long long, uWS::OpCode, void (*)(void*, void*, bool, void*), void*)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:118: undefined reference to `uWS::WebSocket<true>::send(char const*, unsigned long long, uWS::OpCode, void (*)(void*, void*, bool, void*), void*)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:129: undefined reference to `uWS::WebSocket<true>::close(int, char const*, unsigned long long)'
CMakeFiles\path_planning.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:59: undefined reference to `uWS::Group<true>::onMessage(std::function<void (uWS::WebSocket<true>, char*, unsigned long long, uWS::OpCode)>)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:123: undefined reference to `uWS::Group<true>::onConnection(std::function<void (uWS::WebSocket<true>, uWS::HttpRequest)>)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:127: undefined reference to `uWS::Group<true>::onDisconnection(std::function<void (uWS::WebSocket<true>, int, char*, unsigned long long)>)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:134: undefined reference to `uWS::Hub::listen(int, uS::TLS::Context, int, uWS::Group<true>*)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:134: undefined reference to `uS::TLS::Context::~Context()'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:141: undefined reference to `uS::Node::run()'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:134: undefined reference to `uS::TLS::Context::~Context()'
CMakeFiles\path_planning.dir/objects.a(main.cpp.obj): In function `uWS::Hub::Hub(int, bool)':
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/uWebSockets/src/Hub.h:47: undefined reference to `uS::Node::Node(int, int, int, bool)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/uWebSockets/src/Hub.h:47: undefined reference to `uWS::Group<true>::Group(int, uWS::Hub*, uS::NodeData*)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/uWebSockets/src/Hub.h:47: undefined reference to `uWS::Group<false>::Group(int, uWS::Hub*, uS::NodeData*)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/uWebSockets/src/Hub.h:48: undefined reference to `inflateInit2_'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/uWebSockets/src/Hub.h:47: undefined reference to `uS::Node::~Node()'
CMakeFiles\path_planning.dir/objects.a(main.cpp.obj): In function `uWS::Hub::~Hub()':
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/uWebSockets/src/Hub.h:53: undefined reference to `inflateEnd'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/uWebSockets/src/Hub.h:52: undefined reference to `uS::Node::~Node()'
collect2.exe: error: ld returned 1 exit status

I have managed to get the code to work on Windows with the Linux Subsystem; however, this is not what I want because I am unable to use my IDE, CLion, to debug/run the program through the Linux subsystem. How would I change the CMakeLists.txt to get the program to compile and run in Windows 10?

Here is my GNU:

-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Check for working C compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe
-- Check for working CXX compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done

And my CMakeLists.txt:

project(Path_Planning)

cmake_minimum_required(VERSION 3.5)

add_definitions(-std=c++11)

set(CXX_FLAGS "-Wall")
set(CMAKE_CXX_FLAGS, "${CXX_FLAGS}")

set(sources src/main.cpp)

if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")

    include_directories("C:/Program Files/OpenSSL-Win64/include")
    include_directories("C:/Program Files/OpenSSL-Win64/lib")
    include_directories("C:/Program Files/xmrig-deps-4.1/gcc/x64/include")
    include_directories("C:/Program Files/xmrig-deps-4.1/gcc/x64/lib")
    include_directories("C:/Program Files/zlib-1.2.11")

    set(CMAKE_CXX_FLAGS, "${CXX_FLAGS} -fpermissive")

    add_definitions(-D_USE_MATH_DEFINES)
    add_definitions(-fpermissive)
endif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

    include_directories(/usr/local/include)
    include_directories(/usr/local/opt/openssl/include)
    link_directories(/usr/local/lib)
    link_directories(/usr/local/opt/openssl/lib)
    link_directories(/usr/local/Cellar/libuv/1.11.0/lib)

endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")


add_executable(path_planning ${sources})

target_link_libraries(path_planning zlib-1.2.11 OpenSSL-Win64 xmrig-deps-4.1 uWebSockets)
#target_link_libraries(path_planning z ssl uv uWS)

Thank you very much!

EDIT: I have found that CLion actually allows you to use the Linux Subsystem to build directly in your Windows environment, all that you have to is set it up as a remote environment: https://www.jetbrains.com/help/clion/how-to-use-wsl-development-environment-in-clion.html

This allowed me to build and run directly from my windows setup!

Nameless
  • 85
  • 2
  • 10
  • 1
    Have you seen [this](https://stackoverflow.com/questions/8774593/cmake-link-to-external-library) post and its responses for how to include external libraries in your CMake project? You might find these helpful. It looks like you already chose the compiler recommended by this repository for Windows: MinGW. The repository may not build if you choose a different Windows-based compiler. Also, your CMake code appears to be mixing Windows and Linux paths. You probably don't want that, and you should pick one to point to... – Kevin Jun 12 '20 at 14:47
  • I am actually mixing linux and windows paths because I still want my code to be able to compile on linux while I have still not figured how to get the Windows version working. The problem is that the libraries do not contain *.a and *.so so I cannot seem to be able to add them as libraires – Nameless Jun 12 '20 at 14:52
  • Ahhh, you are correct. Well, you may be able to download MinGW versions of these libraries from the internet, or install them directly in the command line alongside the other MinGW tools. Have you tried this? – Kevin Jun 12 '20 at 14:54
  • I have not tried that, though I do not know where I would find such distributables. – Nameless Jun 12 '20 at 15:33
  • You can find them at their respective websites, just google them! Here's is the OpenSSL [distributable](https://wiki.openssl.org/index.php/Binaries). – Kevin Jun 12 '20 at 15:37

0 Answers0