Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED]Linux to Windows port with MinGW  (Read 3977 times)

0 Members and 1 Guest are viewing this topic.

Symphonym

  • Newbie
  • *
  • Posts: 32
    • View Profile
[SOLVED]Linux to Windows port with MinGW
« on: March 08, 2013, 04:47:53 pm »
So I've been working with C++ in Linux for a while, and I feel pretty settled with it as my primary OS. So I started looking into how I can port my projects(SFML projects) over to Windows with SFML.

What I've done is simply a window displaying program, it uses pretty much the default layout found on the website for getting a window running. Runs fine on Linux, so I send it over to my Windows partition, get my Windows .dll files, replace the include directory with the one I got when building it for windows (Although, I don't really need to care about switching include directory, right? It's the same source? :I ).

So lets get to the problem: When I try to compile it on Windows I get a bunch of "undefined reference" errors. I've been googling around for a bit and have yet to find out why. Do I perhaps need to compile SFML libraries specifically for the MinGW's port of the "g++" compiler or should standard Windows built libraries work fine?

Below is the Makefile of my Linux setup:
# Project name goes in the PROJ_NAME variable, it has to be passed
# to the makefile externally

# Default compiler flags and options
CXX := g++
CXXFLAGS := -Iinclude -std=c++11
CXX_DEBUG_FLAGS := -Wl,-R,'$$ORIGIN/lib' -L../debug/lib
CXX_RELEASE_FLAGS := -Wl,-R,'$$ORIGIN/lib' -L../release/lib     \
        -lsfml-audio -lsfml-graphics -lsfml-window -lsfml-network -lsfml-system
src_cpp := $(wildcard *.o)


# Release target, for maximum performance
Release: ${src_cpp}
        ${CXX} -o ../release/${PROJ_NAME} -g *.cpp ${CXX_RELEASE_FLAGS} ${CXXFLAGS} -Wall

# Debug target, uses debug symbols when compiling
Debug: CXXFLAGS += -g
Debug: ${src_cpp}
        ${CXX} -o ../debug/${PROJ_NAME} *.cpp ${CXX_DEBUG_FLAGS} ${CXXFLAGS} -Wall


# For effective, fast and correct compiling(not skipping files):
# specify each .h file that each .o file is dependent on in the
# form of:
# objectfile.o: headerfile.h
 

And the Windows makefile:
# Project name goes in the PROJ_NAME variable, it has to be passed
# to the makefile externally

# Default compiler flags and options
CXX := g++
CXXFLAGS := -Iinclude -std=c++11
CXX_DEBUG_FLAGS := -Wl,-R,'$$ORIGIN/lib' -L../debug/lib
CXX_RELEASE_FLAGS := -Wl,-R,'$$ORIGIN/lib' -L../release/lib  \
        -lsfml-graphics-2 -lsfml-audio-2 -lsfml-window-2 -lsfml-network-2 -lsfml-system-2
src_cpp := $(wildcard *.o)


# Release target, for maximum performance
Release: ${src_cpp}
        ${CXX} -o ../release/${PROJ_NAME} -g *.cpp ${CXX_RELEASE_FLAGS} ${CXXFLAGS} -Wall

# Debug target, uses debug symbols when compiling
Debug: CXXFLAGS += -g
Debug: ${src_cpp}
        ${CXX} -o ../debug/${PROJ_NAME} *.cpp ${CXX_DEBUG_FLAGS} ${CXXFLAGS} -Wall


# For effective, fast and correct compiling(not skipping files):
# specify each .h file that each .o file is dependent on in the
# form of:
# objectfile.o: headerfile.h
 

And finally the error produced can be seen below:
Code: [Select]
C:\Users\XXXXX\Desktop\CrossPlatformTest\src>mingw32-make PROJ_NAME=Wind
owsTest
g++ -o ../release/WindowsTest -g *.cpp -Wl,-R,'$ORIGIN/lib' -L../release/lib
-DSFML_DYNAMIC -lsfml-graphics-2 -lsfml-audio-2 -lsfml-window-2 -lsfml-network-2
 -lsfml-system-2 -Iinclude -std=c++11 -Wall
C:\Users\XXXXX~1\AppData\Local\Temp\cc7MaKMQ.o: In function `main':
C:\Users\XXXXX\Desktop\CrossPlatformTest\src/main.cpp:5: undefined refer
ence to `_imp___ZN2sf9VideoModeC1Ejjj'
C:\Users\XXXXX\Desktop\CrossPlatformTest\src/main.cpp:5: undefined refer
ence to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKSsjRKNS_15ContextSettingsE
'
C:\Users\XXXXX\Desktop\CrossPlatformTest\src/main.cpp:13: undefined refe
rence to `_imp___ZN2sf6Window5closeEv'
C:\Users\XXXXX\Desktop\CrossPlatformTest\src/main.cpp:10: undefined refe
rence to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
C:\Users\XXXXX\Desktop\CrossPlatformTest\src/main.cpp:16: undefined refe
rence to `_imp___ZN2sf5ColorC1Ehhhh'
C:\Users\XXXXX\Desktop\CrossPlatformTest\src/main.cpp:16: undefined refe
rence to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'
C:\Users\XXXXX\Desktop\CrossPlatformTest\src/main.cpp:17: undefined refe
rence to `_imp___ZN2sf6Window7displayEv'
C:\Users\XXXXX\Desktop\CrossPlatformTest\src/main.cpp:7: undefined refer
ence to `_imp___ZNK2sf6Window6isOpenEv'
C:\Users\XXXXX\Desktop\CrossPlatformTest\src/main.cpp:20: undefined refe
rence to `_imp___ZN2sf12RenderWindowD1Ev'
C:\Users\XXXXX\Desktop\CrossPlatformTest\src/main.cpp:20: undefined refe
rence to `_imp___ZN2sf12RenderWindowD1Ev'
collect2.exe: fel: ld returnerade avslutningsstatus 1
makefile:15: recipe for target 'Release' failed
mingw32-make: *** [Release] Error 1


What am I doing wrong?
« Last Edit: March 08, 2013, 06:01:20 pm by Symphonym »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Linux to Windows port with MinGW
« Reply #1 on: March 08, 2013, 04:59:05 pm »
The import libraries don't have the "-2" suffix on Windows (only the DLLs have), so it shouldn't appear in your makefile.
Laurent Gomila - SFML developer

Symphonym

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Linux to Windows port with MinGW
« Reply #2 on: March 08, 2013, 05:17:48 pm »
The import libraries don't have the "-2" suffix on Windows (only the DLLs have), so it shouldn't appear in your makefile.

Wait, been away from Windows too long. I checked my directory of the built SFML, and I've got ".lib", ".dll", and ".exp". Which of these should I place in my "lib" folder? I'm a bit confused right now, Linux is simple: .so (dynamic/shared lib), .a (static lib). I might need a quick refresher on Windows libs :/

Edit: Removing the "-2"'s and having both .dll files and .lib files in my "lib" folder gives the same error.
« Last Edit: March 08, 2013, 05:19:55 pm by Symphonym »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Linux to Windows port with MinGW
« Reply #3 on: March 08, 2013, 05:35:05 pm »
Wait, what version of SFML are you using? :o
The MinGW version doesn't have any .lib files, those are only for VS.

On Windows the endings are as follows:
MinGW: .a import library OR static library; .dll shared library; it's also common to use .dll.a for import libraries
VS: .lib import library OR static library; .dll shared library
« Last Edit: March 08, 2013, 05:36:39 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Symphonym

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Linux to Windows port with MinGW
« Reply #4 on: March 08, 2013, 06:01:07 pm »
Wait, what version of SFML are you using? :o
The MinGW version doesn't have any .lib files, those are only for VS.

On Windows the endings are as follows:
MinGW: .a import library OR static library; .dll shared library; it's also common to use .dll.a for import libraries
VS: .lib import library OR static library; .dll shared library

This helped clearing up my mind. I had been using the same library files that I use when natively developing on windows, in other words: I selected "Visual Studio" when using CMake to generate the project files and then using Visual Studio to build them. I now selected "MinGW makefiles" in CMake, built those with mingw32-make and there we go. Problem solved.

void

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: [SOLVED]Linux to Windows port with MinGW
« Reply #5 on: March 13, 2013, 01:41:51 pm »
Not a direct help, but take a look at cmake. It takes problems like that from you. I use it for Linux and Windows.