Hello there! I have been trying to compile the following code in Code::Blocks
#include <iostream>
#include <SFML/Network.hpp>
using namespace sf;
using namespace std;
int main(){
cout << "Would you like to be a server or client? (s/c)" << endl;
char choice;
cin >> choice;
if(choice == 's'){
TcpListener listener;
listener.listen(1337);
std::string message = "";
Packet serverPacket;
while(true){
TcpSocket client;
if(listener.accept(client) == Socket::Done){
cout << "Client has connected from " << client.getRemoteAddress() << endl;
cout << "Send message to client: ";
cin >> message;
serverPacket << message;
client.send(serverPacket);
}
}
}else{
Packet clientPacket;
std::string messageSent;
TcpSocket socket;
if(socket.connect("localhost", 1337)){
cout << "Unable to find server." << endl;
}else{
cout << "Connected to server!" << endl;
}
while(true){
socket.receive(clientPacket);
if(clientPacket >> messageSent){
cout << "[Server] " << messageSent << endl;
}
}
}
return 0;
}
I have followed the tutorial for SFML 2.0 on Windows using Code::Blocks and can run most applications I make fine.
I have only added sfml-graphics-s, sfml-window-s and sfml-system-s and their debugging equivalents to my linker options, am I suppose to add sfml-network-s to make this code compile and run correctly? :)
The reason I have not tried this myself already is because I'm not sure if sfml-network-s even exists and if it does what order I would add it into the linker options.
Thanks for reading. :)
I knew the order on that tutorial. I just didn't see an sfml-network or anything on there so I wouldn't have known where to put that.
I have tried compiling and running the following code:
#include <SFML/Network.hpp>
using namespace sf;
int main(){
sf::TcpListener listener;
return 0;
}
And I get the errors:
-------------- Build: Debug in SFML Networtk (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -g -I..\..\..\Downloads\SFML-2.0-rc\include -I"C:\Program Files\CodeBlocks\include" -c "C:\Users\newowner\Desktop\C++\SFML Networtk\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe -L..\..\..\Downloads\SFML-2.0-rc\lib -L"C:\Program Files\CodeBlocks\lib" -o "bin\Debug\SFML Networtk.exe" obj\Debug\main.o -lsfml-graphics-d -lsfml-window-d -lsfml-system-d -lmingw32
obj\Debug\main.o: In function `main':
C:/Users/newowner/Desktop/C++/SFML Networtk/main.cpp:6: undefined reference to `_imp___ZN2sf11TcpListenerC1Ev'
obj\Debug\main.o: In function `~TcpListener':
C:\Users\newowner\Desktop\C++\SFML Networtk/../../../Downloads/SFML-2.0-rc/include/SFML/Network/TcpListener.hpp:43: undefined reference to `_imp___ZTVN2sf11TcpListenerE'
C:\Users\newowner\Desktop\C++\SFML Networtk/../../../Downloads/SFML-2.0-rc/include/SFML/Network/TcpListener.hpp:43: undefined reference to `_imp___ZN2sf6SocketD2Ev'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 3 seconds)
3 errors, 0 warnings (0 minutes, 3 seconds)
It works fine before I add a TcpListener, any ideas?