I'm trying to use MinGW to cross compile from Linux to Windows a robotic controller (.exe) for Webots (simulation software).
Webots supplies a Makefile.include
file common to all platforms, that prepares the building environment for compilation (necessary dependencies):
My current makefile, where I set several variables according to MinGW and my webots installation:
WEBOTS_HOME = /usr/share/webots/resources/windows_home
#WEBOTS_HOME = /usr/share/webots
RESOURCES_PATH = $(WEBOTS_HOME)/resources/projects/robots/darwin-op
SOURCES_PATH = src
SOCKET_PATH = ../../../extra/socket/src
KIN_INCLUDE = ../../lib/OPKinematics/include
KIN_LIB = ../../lib/OPKinematics/lib/libOPKinematics64.a
EXT_INCLUDE = ../../lib/include
CFLAGS = -g -Wall
INCLUDE=-I$(RESOURCES_PATH)/libraries/darwin/darwin/Framework/include -I$(RESOURCES_PATH)/include -I$(KIN_INCLUDE) -I$(EXT_INCLUDE) -I$(SOCKET_PATH)
LIBRARIES = -Wl,-Bstatic -lws2_32 -lpthread -lboost_system-mt -lboost_serialization-mt -static-libgcc -static-libstdc++ -Wl,-Bdynamic $(RESOURCES_PATH)/libraries/darwin/darwin.dll $(KIN_LIB)
CXX_SOURCES = $(SOURCES_PATH)/main.cpp $(SOURCES_PATH)/DarwinRobot.cpp $(SOURCES_PATH)/dyn_system.cpp $(SOURCES_PATH)/writefilestuff.cpp $(SOCKET_PATH)/socket_boost.cpp
#CC=x86_64-w64-mingw32-g++
CXX=x86_64-w64-mingw32-g++
EXE_EXTENSION=.exe
OSTYPE=windows
CFLAGS += -DWIN_MAKE
# ----------------------------------------------------
#
### Do not modify: this includes Webots global Makefile.include
space :=
space +=
WEBOTS_HOME_PATH=$(subst $(space),\ ,$(strip $(subst \,/,$(WEBOTS_HOME))))
include $(WEBOTS_HOME_PATH)/resources/Makefile.include
# No pre or post build rules are necessary, override the default set on Makefile.include
pre-build: ;
post-build: main-build ;
@echo $(CC)
@echo $(OSTYPE)
# ---------------------------------------------------
Additionaly, I've installed Webots on my Windows box and copied the installation folder to the installation folder on my Linux box, so that I could have access to the pre-compiled Windows libraries.
The problem is when the linker tries to find a couple of libraries (-lController
and -lCppController
, which are appended inside Makefile.include
):
# linking build/release/darwin_socket.exe
x86_64-w64-mingw32-g++ -s -Wl,--enable-auto-import -o build/release/darwin_socket.exe build/release/main.o build/release/DarwinRobot.o build/release/dyn_system.o build/release/writefilestuff.o build/release/socket_boost.o -Wl,-Bstatic -lws2_32 -lpthread -lboost_system-mt -lboost_serialization-mt -static-libgcc -static-libstdc++ -Wl,-Bdynamic /usr/share/webots/resources/windows_home/resources/projects/robots/darwin-op/libraries/darwin/darwin.dll ../../lib/OPKinematics/lib/libOPKinematics64.a -lmingw32 -B"/usr/share/webots/resources/windows_home\mingw\lib\gcc\mingw32\5.1.0" -L"/usr/share/webots/resources/windows_home/lib" -lController -lCppController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/libController.a when searching for -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/Controller.lib when searching for -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/Controller.dll when searching for -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/libController.a when searching for -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/libController.a when searching for -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/Controller.lib when searching for -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/Controller.dll when searching for -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/Controller.lib when searching for -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32 /bin/ld: cannot find -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/libCppController.a when searching for -lCppController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/CppController.dll when searching for -lCppController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/libCppController.a when searching for -lCppController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/libCppController.a when searching for -lCppController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/CppController.dll when searching for -lCppController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lCppController
collect2: error: ld returned 1 exit status
/usr/share/webots/resources/windows_home/resources/Makefile.include:529: recipe for target 'build/release/darwin_socket.exe' failed
make: *** [build/release/darwin_socket.exe] Error 1
From what I've gathered, this issue is usually caused when trying to link 32-bit libraries to a 64-bit binary (or vice-versa), but I have no -m32
or -m64
flags on my makefile or on Makefile.include
. My OSs are both 64-bit, so I assume there should not be any problem with the type of libraries.
I've tried using Webots' native linux installation folder instead, but I encounter similar issues:
# linking build/release/darwin_socket.exe
x86_64-w64-mingw32-g++ -s -Wl,--enable-auto-import -o build/release/darwin_socket.exe build/release/main.o build/release/DarwinRobot.o build/release/dyn_system.o build/release/writefilestuff.o build/release/socket_boost.o -Wl,-Bstatic -lws2_32 -lpthread -lboost_system-mt -lboost_serialization-mt -static-libgcc -static-libstdc++ -Wl,-Bdynamic /usr/share/webots/resources/projects/robots/darwin-op/libraries/darwin/darwin.dll ../../lib/OPKinematics/lib/libOPKinematics64.a -lmingw32 -B"/usr/share/webots\mingw\lib\gcc\mingw32\5.1.0" -L"/usr/share/webots/lib" -lController -lCppController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lCppController
collect2: error: ld returned 1 exit status
/usr/share/webots/resources/Makefile.include:529: recipe for target 'build/release/darwin_socket.exe' failed
make: *** [build/release/darwin_socket.exe] Error 1
which is rather strange, because both libController.so
and libCppController.so
are present inside /usr/share/webots/lib/
.
So what exactly am I missing here?