![]() |
|
#1
|
||||
|
||||
G++ question...Hi All,
This is my first post on these forums, and I'm hoping some of you can help me. First of all, I'm a Java guy, but I've dabbled in C and C++ in the past. I've purchased a book called "Multiplayer Game Programming" in which the author uses C++ as his laguage of choice. The author of this book assumes that the reader is using Microsoft's Visual Studio, and steps the reader through to associate libraries and what not inside that software package so that his code with compile properly. I don't have Visual Studio, and I'm trying to compile and link his programs using g++ at the command line. His first program is a Simple ClientConnectionTest program that uses winsock2.h. He (along with everything I could find on the internet) said that you must associate the library ws2_32.lib to this build. Is there any way to associate this library on the command prompt for g++ without creating a makefile. Thanks, Trey |
|
#2
|
||||
|
||||
Re: G++ question...What software package are you using?
For mingw: -lws2_32 For Cygwin: do the same but also add -mno-cygwin That should do the trick. |
|
#3
|
||||
|
||||
Re: G++ question...Thanks for the help. That did get rid of some of the compiler errors I was getting that I thought were associated with not linking that library. however some more have cropped up. I am using cygwin by the way, so the command I used was "g++ -lws2_32 -mno-cygwin ConnectionTest.cpp". I struggled with this for a couple of hours last night, so I'm quite frustrated with it. So, maybe you can help me along to get this compiled. I truly appreciate all of the help.
I'm just not used to the compiler errors that the g++ compiler is giving me. That comes with use as we all know. I just don't know what it's trying to tell me know. Here are the NEW compiler errors (it's almost like it doesn't see the SocketObject header file). Code:
Here is some of the code (the SocketObject.h): CPP / C++ / C Code:
That was all of the code... but all I was wanting you to see was the SocketObject class. This next code is what the error messages are actually referring to. It's got to be something to with the includes, but I put the whole file there in case you are curious. I'm nt sure why all of the Socket Objects are getting the "undefined reference" error? Help? Here is the ConnectionTest.c file: CPP / C++ / C Code:
Last edited by cable_guy_67 : 23-Feb-2006 at 12:29.
Reason: Please enclose c++ code in [c++] ... [/c++] tags
|
|
#4
|
||||
|
||||
Re: G++ question...Do you by any chance have a SocketObject.cpp file somewhere that could be compiled with the rest...
Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#5
|
||||
|
||||
Re: G++ question...I thought it would probably be something simple to do with my lack of knowledge of the linker. I'm so spoiled by Java. I'm still getting several undefined reference errors.
g++ -mno-cygwin -lws2_32 ConnectionTest.cpp SocketObject.cpp There's probably something I'm not doing right. Are there other libraries I need? IS that the proper syntax or order for the command? Here is a sampling of some of the errors that I'm getting now. Some went away... but more new ones came. Gotta love when that happens: SocketObject.cpp: In member function `bool SocketObject::Connect(char*, int)': SocketObject.cpp:168: warning: converting to non-pointer type `char' from NULL SocketObject.cpp:181: warning: passing NULL used for non-pointer converting 2 of `void* CreateThread(_SECURITY_ATTRIBUTES*, DWORD, DWORD (*)(void*), void*, DWOR D, DWORD*)' SocketObject.cpp:181: warning: passing NULL used for non-pointer converting 5 of `void* CreateThread(_SECURITY_ATTRIBUTES*, DWORD, DWORD (*)(void*), void*, DWORD, DWORD*)' SocketObject.cpp: In member function `bool SocketObject::Accept(SocketObject&)': SocketObject.cpp:244: warning: converting to non-pointer type `char' from NULL SocketObject.cpp:257: warning: passing NULL used for non-pointer converting 2 of `void* CreateThread(_SECURITY_ATTRIBUTES*, DWORD, DWORD (*)(void*), void*, DWORD, DWORD*)' SocketObject.cpp:257: warning: passing NULL used for non-pointer converting 5 of `void* CreateThread(_SECURITY_ATTRIBUTES*, DWORD, DWORD (*)(void*), void*, DWORD, DWORD*)' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccb1ZaF7.o:ConnectionTest.cpp: (.text+0x2dc): undefined reference to `_WSACleanup@0' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x34): undefined reference to `_WSAStartup@8' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x78 ): undefined reference to `_WSAStartup@8' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x27b): undefined reference to `_recv@16' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x395): undefined reference to `_send@16' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x3d1): undefined reference to `_inet_addr@4' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x3e8 ): undefined reference to `_gethostbyname@4' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x40f): undefined reference to `_WSASetLastError@4' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x42c): undefined reference to `_htons@4' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x452): undefined reference to `_socket@12' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x487): undefined reference to `_connect@12' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x547): undefined reference to `_closesocket@4' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x57c): undefined reference to `_socket@12' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x5c2): undefined reference to `_htonl@4' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x5d6): undefined reference to `_htons@4' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x5f9): undefined reference to `_bind@12' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x63f): undefined reference to `_listen@8' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x670): undefined reference to `_accept@12' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x77c): undefined reference to `_recv@16' /cygdrive/c/DOCUME~1/TREY~1.WHI/LOCALS~1/Temp/ccqprnsj.o:SocketObject.cpp: (.text+0x7aa): undefined reference to `_send@16' |
|
#6
|
||||
|
||||
Re: G++ question...Your source code is incomplete. You should look through the book, (maybe in the back). It should have the source code for the class in there to. If you have the code to that class please post it so we can have a look
You could try manually linking "libws2_32.a" make sure that that file is in your cygwin/lib/w32api folder as well. |
|
#7
|
||||
|
||||
Re: G++ question...Ok... here is all the code.
Driver file (TestConnection.c): CPP / C++ / C Code:
Socket Object Header File (SocketObject.h) CPP / C++ / C Code:
SocketObject Source File (SocketObject.cpp) CPP / C++ / C Code:
That's all there is to it. The book mentions that in Visual Studio you need to link to the ws2_32.lib (which I think we have done)... so it must something else. |
|
#8
|
||||
|
||||
Re: G++ question...Your code (with a few name changes) compiles with a number of warnings for me.
Code:
Run Code:
Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#9
|
||||
|
||||
Re: G++ question...Yeah... I just got it working on my computer as well. To get it working over here, we simply had to change the order of arguments to g++... the -lws2_32 must be last.
This command build (with warnings, but no errors): g++ -mno-cygwin ConnectionTest.cpp ../SocketObject/SocketObject.cpp -lws2_32 Before, I was putting the -l command before the source files. That changed everything. Just out of curiosity, what changes did you make to get it working? |
|
#10
|
||||
|
||||
Re: G++ question...I created everything in a common directory and saved off your files with my normal naming convention. Nothing that changed anything you were doing.
As far as working, I think there is more to do. It runs with no arguments passed but I was getting a crash when passing args in(progname client ip). If you have problems, let us know what you are using as test values. Mark BTW, I looked up the book you were talking about on Amazon. If I got it right, it sounds like you are going to run into quite a few problems with the source code. You may want to see if there is an updated source package at the publishers website. It may save you some headaches. __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
Recent GIDBlog
Developing GUIs with wxPython (Part 3) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Borland compile question | monnick | C++ Forum | 4 | 12-Feb-2006 17:40 |
| non-member function question | crq | C++ Forum | 1 | 03-Feb-2005 21:59 |
| Simple question on arrays--please help! | brookeville | C++ Forum | 16 | 17-Nov-2004 23:23 |
| Repetition structure problem and question | brookeville | C++ Forum | 17 | 29-Oct-2004 17:48 |
| question of practice | magiccreative | C++ Forum | 1 | 06-Feb-2004 07:17 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The