Page 1 of 1

Linking with files from another project

Posted: Mon Sep 27, 2010 4:55 pm
by Hnry
I have divided my project to have two other projects(Common, Connection) that are used by other projects(Login, World) and they are all in the same workspace. Build order should be correct as it is now but there are still "undefined references to" functions/classes.

Build output:

Code: Select all

----------Build Started--------
C:\Windows\system32\cmd.exe /c ""mingw32-make.exe"  -j 1 -f "Flyff_wsp.mk""
----------Building project:[ Common - Debug ]----------
mingw32-make.exe[1]: Entering directory `C:/Flyff/Common'
mingw32-make.exe[1]: Leaving directory `C:/Flyff/Common'
----------Building project:[ Connection - Debug ]----------
mingw32-make.exe[1]: Entering directory `C:/Flyff/Connection'
mingw32-make.exe[1]: Leaving directory `C:/Flyff/Connection'
----------Building project:[ Login - Debug ]----------
mingw32-make.exe[1]: Entering directory `C:/Flyff/Login'
mingw32-make.exe[1]: `C:\Flyff\Common\Precompiled.h.gch' is up to date.
mingw32-make.exe[1]: Leaving directory `C:/Flyff/Login'
mingw32-make.exe[1]: Entering directory `C:/Flyff/Login'
g++ -o ./Debug/Login ./Debug/main.o ./Debug/Initializing.o ./Debug/Server.o ./Debug/Player.o ./Debug/Items.o ./Debug/Worlds.o ./Debug/PacketCreator.o ./Debug/LoginPacket.o ./Debug/Login.o ./Debug/Characters.o  "-L."  -lwsock32  
./Debug/main.o: In function `main':
C:/Flyff/Login/main.cpp:27: undefined reference to `Selector::Selector()'
C:/Flyff/Login/main.cpp:28: undefined reference to `Acceptor::Acceptor(int, Selector*, AbstractPlayerFactory*)'
C:/Flyff/Login/main.cpp:29: undefined reference to `Acceptor::Acceptor(int, Selector*, AbstractPlayerFactory*)'
C:/Flyff/Login/main.cpp:35: undefined reference to `Selector::~Selector()'
C:/Flyff/Login/main.cpp:35: undefined reference to `Selector::~Selector()'
./Debug/main.o: In function `~AbstractPlayer':
C:/Flyff/Login/../Connection/AbstractPlayer.h:13: undefined reference to `vtable for AbstractPlayer'
./Debug/main.o: In function `AbstractPlayer':
C:/Flyff/Login/../Connection/AbstractPlayer.h:8: undefined reference to `vtable for AbstractPlayer'
./Debug/Player.o:Player.cpp:(.rdata$_ZTV6Player[vtable for Player]+0x8): undefined reference to `AbstractPlayer::setPacketHandler(PacketHandler*)'
./Debug/PacketCreator.o:C:/Flyff/Login/Player.h:163: undefined reference to `PacketHandler::sendPacket(unsigned char*, int)'
collect2: ld returned 1 exit status
mingw32-make.exe[1]: *** [Debug/Login] Error 1
mingw32-make.exe[1]: Leaving directory `C:/Flyff/Login'
mingw32-make.exe: *** [All] Error 2
----------Build Ended----------
1 errors, 0 warnings

I'm pretty sure my problem is that I'm not including my other projects' object files to linker because the object files from Connection aren't shown here:

Code: Select all

g++ -o ./Debug/Login ./Debug/main.o ./Debug/Initializing.o ./Debug/Server.o ./Debug/Player.o ./Debug/Items.o ./Debug/Worlds.o ./Debug/PacketCreator.o ./Debug/LoginPacket.o ./Debug/Login.o ./Debug/Characters.o  "-L."  -lwsock32
I figured adding

Code: Select all

../Connection/Debug/AbstractPlayer.o ../Connection/Debug/Acceptor.o ../Connection/Debug/PacketHandler.o ../Connection/Debug/Selector.o
there could be a solution but I don't know how to do it.


Thanks in advance,
Hnry

Re: Linking with files from another project

Posted: Mon Sep 27, 2010 7:20 pm
by eranif
You should create a library from project 'Connection' (change the type of project 'Connection' to 'Static Library' / 'Dynamic Library') and use the output of this project in the link option of the other project

Eran

Re: Linking with files from another project

Posted: Mon Sep 27, 2010 7:25 pm
by Hnry
Damn, didn't even think about that. That's simple then. :)