Thread: Porting a shared library from Linux to Windows

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    22

    Question Porting a shared library from Linux to Windows

    Hey guys!

    First of all, thanks a lot for helping me through all this time, you all rock!

    Now though, I'm trying to port my game library from Linux to Windows but it's been a small pain-in-the-you-know-what :/ for instance, here's the Linux makefile:

    Code:
    CFLAGS=-I. -I/usr/include/freetype2
    
    all: main
    
    main:
    	g++ $(CFLAGS) -c -o core.o      lib/core.cpp
    	g++ $(CFLAGS) -c -o 3dmath.o    lib/3dmath.cpp
    	g++ $(CFLAGS) -c -o audio.o     lib/audio.cpp
    	g++ $(CFLAGS) -c -o camera.o    lib/camera.cpp
    	g++ $(CFLAGS) -c -o sprite.o    lib/sprite.cpp
    	g++ $(CFLAGS) -c -o freetype.o  lib/freetype.cpp
    	g++ $(CFLAGS) -c -o fps.o       lib/fps.cpp
    	g++ $(CFLAGS) -c -o collision.o lib/collision.cpp
    	ld -o libgp2d.so core.o camera.o 3dmath.o sprite.o freetype.o fps.o audio.o collision.o -shared
    	rm *.o
    clean:
    	rm *.o
    	rm libgp2d.so
    And here's the Windows one (that I had to hack around with lots of googling):

    Code:
    CFLAGS=-I.
    
    all: main
    
    main:
    	g++ $(CFLAGS) -c -o core.o      lib/core.cpp
    	g++ $(CFLAGS) -c -o 3dmath.o    lib/3dmath.cpp
    	g++ $(CFLAGS) -c -o audio.o     lib/audio.cpp
    	g++ $(CFLAGS) -c -o camera.o    lib/camera.cpp
    	g++ $(CFLAGS) -c -o sprite.o    lib/sprite.cpp
    	g++ $(CFLAGS) -c -o freetype.o  lib/freetype.cpp
    	g++ $(CFLAGS) -c -o fps.o       lib/fps.cpp
    	g++ $(CFLAGS) -c -o collision.o lib/collision.cpp
    #	ar rcs libgp2d.a core.o camera.o 3dmath.o sprite.o freetype.o fps.o audio.o collision.o
    	g++ -Wl -o libgp2d.so core.o camera.o 3dmath.o sprite.o freetype.o fps.o audio.o collision.o -lmingw32 -lSDL -lSDL_image -lSDL_mixer -lopengl32 -lfreetype -mwindows -lwinmm
    
    	del *.o
    clean:
    	del *.o
    	del libgp2d.so
    The commented line is the one that works, I get the .a file, but it doesn't get recognized when I compile my game itself... it throws something like this:

    Code:
    C:\SVN\iteam>make -f Makefile.win
    g++ -o iteam.exe iteam.cpp functions.cpp players.cpp -Bdynamic -I. -L. -I/usr/include/freetype2 -L/lib -lGP2D -lfreetype -lSDL -lSDL_mixer -lSDL_image -lope
    ngl -lglu32 -lmingw32 -mwindows
    In file included from iteam.cpp:1:
    globals.h:24: error: expected init-declarator before "FNTCounter"
    globals.h:24: error: expected `,' or `;' before "FNTCounter"
    globals.h:25: error: expected init-declarator before "FNTNames"
    globals.h:25: error: expected `,' or `;' before "FNTNames"
    globals.h:26: error: expected init-declarator before "FNTGameGUI"
    globals.h:26: error: expected `,' or `;' before "FNTGameGUI"
    iteam.cpp:18: error: expected constructor, destructor, or type conversion before "iteam"
    iteam.cpp:18: error: expected `,' or `;' before "iteam"
    iteam.cpp:19: error: expected constructor, destructor, or type conversion before "iteam"
    iteam.cpp:19: error: expected `,' or `;' before "iteam"
    iteam.cpp:20: error: expected constructor, destructor, or type conversion before "iteam"
    iteam.cpp:20: error: expected `,' or `;' before "iteam"
    In file included from functions.cpp:1:
    globals.h:24: error: expected init-declarator before "FNTCounter"
    globals.h:24: error: expected `,' or `;' before "FNTCounter"
    globals.h:25: error: expected init-declarator before "FNTNames"
    globals.h:25: error: expected `,' or `;' before "FNTNames"
    globals.h:26: error: expected init-declarator before "FNTGameGUI"
    globals.h:26: error: expected `,' or `;' before "FNTGameGUI"
    functions.cpp: In function `int iteam::Load()':
    functions.cpp:29: error: `FNTCounter' undeclared (first use this function)
    functions.cpp:29: error: (Each undeclared identifier is reported only once for each function it appears in.)
    functions.cpp:30: error: `FNTNames' undeclared (first use this function)
    functions.cpp:31: error: `FNTGameGUI' undeclared (first use this function)
    functions.cpp: In function `void iteam::DrawGUI()':
    functions.cpp:83: error: `FNTGameGUI' undeclared (first use this function)
    functions.cpp:83: error: `Text' undeclared (first use this function)
    In file included from players.cpp:1:
    globals.h:24: error: expected init-declarator before "FNTCounter"
    globals.h:24: error: expected `,' or `;' before "FNTCounter"
    globals.h:25: error: expected init-declarator before "FNTNames"
    globals.h:25: error: expected `,' or `;' before "FNTNames"
    globals.h:26: error: expected init-declarator before "FNTGameGUI"
    globals.h:26: error: expected `,' or `;' before "FNTGameGUI"
    players.cpp: In member function `void iteam::PlayerObj::DrawName()':
    players.cpp:23: error: `FNTNames' undeclared (first use this function)
    players.cpp:23: error: (Each undeclared identifier is reported only once for each function it appears in.)
    players.cpp:23: error: `Text' undeclared (first use this function)
    make: *** [main] Error 1
    
    C:\SVN\iteam>
    So... either I get that... or with the g++ line in the Makefile, I get this:

    Code:
    C:\SVN\gp2d>make -f Makefile.win
    g++ -I. -c -o core.o      lib/core.cpp
    g++ -I. -c -o 3dmath.o    lib/3dmath.cpp
    g++ -I. -c -o audio.o     lib/audio.cpp
    g++ -I. -c -o camera.o    lib/camera.cpp
    g++ -I. -c -o sprite.o    lib/sprite.cpp
    g++ -I. -c -o freetype.o  lib/freetype.cpp
    g++ -I. -c -o fps.o       lib/fps.cpp
    g++ -I. -c -o collision.o lib/collision.cpp
    g++ -shared -Wl -o libgp2d.so core.o camera.o 3dmath.o sprite.o freetype.o fps.o audio.o collision.o -lmingw32 -lSDL -lSDL_image -lSDL_mixer -lopengl32 -lfr
    eetype -mwindows -lwinmm
    Cannot export ⌂SDL_image_NULL_THUNK_DATA: symbol not found
    Cannot export ⌂SDL_mixer_NULL_THUNK_DATA: symbol not found
    collect2: ld returned 1 exit status
    make: *** [main] Error 1
    
    C:\SVN\gp2d>
    If I remove the -shared parameter, I get this:

    Code:
    C:\SVN\gp2d>make -f Makefile.win
    g++ -I. -c -o core.o      lib/core.cpp
    g++ -I. -c -o 3dmath.o    lib/3dmath.cpp
    g++ -I. -c -o audio.o     lib/audio.cpp
    g++ -I. -c -o camera.o    lib/camera.cpp
    g++ -I. -c -o sprite.o    lib/sprite.cpp
    g++ -I. -c -o freetype.o  lib/freetype.cpp
    g++ -I. -c -o fps.o       lib/fps.cpp
    g++ -I. -c -o collision.o lib/collision.cpp
    g++ -Wl -o libgp2d.so core.o camera.o 3dmath.o sprite.o freetype.o fps.o audio.o collision.o -lmingw32 -lSDL -lSDL_image -lSDL_mixer -lopengl32 -lfreetype -
    mwindows -lwinmm
    /mingw/lib/libmingw32.a(main.o):main.c:(.text+0x106): undefined reference to `WinMain@16'
    collect2: ld returned 1 exit status
    make: *** [main] Error 1
    
    C:\SVN\gp2d>
    Which is unlogical because the library has no need for a main sentence (not that I know of) because it has worked perfectly in Linux without one.

    If anybody could lend me a hand here it would be GREATLY appreciated!

    - DARKGuy

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    you are trying to make an so file in windows. Windows doesn't use so files, it uses dlls. http://www.mingw.org/docs.shtml#compilingandbuilding

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Shared library design problem
    By p1r0 in forum C++ Programming
    Replies: 9
    Last Post: 03-23-2009, 12:36 PM
  2. stdio differences windows vs linux
    By keira in forum C Programming
    Replies: 6
    Last Post: 09-14-2008, 04:42 PM
  3. Convert Windows GUI to Linux GUI
    By BobS0327 in forum Linux Programming
    Replies: 21
    Last Post: 11-27-2005, 04:39 AM
  4. Replies: 1
    Last Post: 10-18-2005, 10:20 AM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM