First time compile error - winsock.h

  • Paudatoi
    1st Sep 2012 Member 0 Permalink

    Hi,

    this is the output I got from a first time compile on Win7 64Bit (Visual Studio Express). I followed the tutorial on the wiki as good as I can.

     

    http://pastebin.com/raw.php?i=WazPyjnG

     

    Could someone help me out what went wrong?

    I do know that winsock has something to do with the internet connectivity of TPT (and in general) but I have no clue what to do to get around the errors in the build log to have a clean compile.

  • abczyx123987
    1st Sep 2012 Member 0 Permalink
    Oh, no, not this problem again...
    It's happened to a couple of people in the past, but I have no clue what could be causing this.

    The one thing I might suggest is starting over from scratch, and this time following the wiki very carefully.
    In the meantime, I have a hunch as to what might be causing the problem, so I'm going to look into it right now....
  • Paudatoi
    1st Sep 2012 Member 0 Permalink

    Thanks for your help so far and taking the time to find a solution :). In the meantime, I've googled a bit and it seems that there is a conflict between winsock.h and winsock2.h. It seems that somewhere in the 'include tree' both are included and thus clash (more specifically somewhere windows.h gets called which calls winsock.h which then clashes with winsock2.h).

     

    Some people got the exact same error and one guy solved it but his solution is not applicable here, I think since TPT is not using wxWidgets (which is, from what I understand, a GUI framework?) and using the mentioned #define WIN32_LEAN_AND_MEAN trick did not work here:

    http://forums.codeguru.com/showthread.php?286587-Errors-C2011-and-C2375-when-using-winsock2.h&s=7297e24e95576fdb1ce90e25b9b3574f&p=915045#post915045

     

    Summing up, it might be possible that somewhere the 'old' winsock.h gets included (via windows.h or other include files) and that it clashes with the 'new' winsock2.h. It is possible that the include of winsock.h is several levels deep. I haven't been able to find it in the project files.

    The only include of windows.h I was able to find is in bzlib.h - winsock.h did not figure anywhere in the source.

    I hope that this helps (to help me that is ;)).

  • abczyx123987
    1st Sep 2012 Member 0 Permalink
    Yeah, I already knew that winsock.h and winsock2.h weren't compatible, but I've just never been able to figure out how they could've both gotten included while compiling (I've even run the MSVC++ preprocessor through the entire source code in the past and I've never found it getting included).

    My previous hunch turned out to be incorrect, too, so...

    If you still have the project file that's not working, could you send it to me? (just upload it somewhere and give me the link) I'd really like to get to the bottom of this.

    It should be possible to compile TPT without adding WIN32_LEAN_AND_MEAN to the preprocessor definitions.
    (In fact, I just did it myself)
    You could try it, though, to see if it works for you...
  • Paudatoi
    1st Sep 2012 Member 0 Permalink

    @abczyx123987 (View Post)

    ok, I'll retry to follow the instructions (am a bit tired here so maybe there was a mistake - but I already tried two times before, but we'll see) and if it does not work, I'll post you a link to the zipped project.

     

    ----------------------

     

    new post (no double-posts allowed):

     

    k, no workey ..... :-/ - here's the zip:

    http://minus.com/lqpGSgANEIhwE

     

    by the way: when I cut&paste several include lines down after http.h (where the 'new' winsock2.h gets called), it spews out the errors much earlier (after going through http.c and interface.c).

     

    I moved down these include lines after http.h: pthread.h, bzlib.h and misc.h (all possible culprits for calling windows.h --> winsock.h). I moved them because one solution on the net said that when calling (directly or indirectly) winsock2.h first, there should be no problems.

     

    Curiously enough when I move them back up (above http.h) or down again, I always get the errors early on (after http.c and interface.c). But it could just be, that VC tries to recompile the changed files first so that the errors come earlier. I hope I am making some sense here (English is not my native language).

    And thanks again for helping me with this compile issue!

  • Pilihp64
    2nd Sep 2012 Developer 0 Permalink

    I think I did have this problem one time, but I don't remember the solution.

     

    If you read the wiki you know that there is a link to a working full visual studio project that compiles without any issues.  All you might need to do is update the source and add newer files to the project.  If you wait a minute I'll go ahead and update the project to the latest.

    EDIT: Ok, I updated the project link to be latest github, just after v82.  The v83 beta is an entirely different source and doesn't compile nicely on visual studio yet.

  • Paudatoi
    2nd Sep 2012 Member 0 Permalink

    @cracker64 (View Post)

    I just tried the premade build by you. Compiling it works fine now, thanks! I still hope that the other problem gets resolved so that the wiki instructions work for all people (including people with strange problems like me ;)).
    I am just starting with all the C-programming stuff so I thought it would be a good idea to go the more complex route (although a well explained one ;)) to learn how to do things. That is why I did not use the premade build in the beginning.

     

    P.S.: The build didn't like one of my former stamps though, crashed - but was nothing big, redrawing it and then it worked no problem (if you need the stamps (just a few lines, dabbling around with yeast growth) for debugging or similar, just tell me).

  • abczyx123987
    2nd Sep 2012 Member 0 Permalink
    I've finally figured out what went wrong (and what's causing those errors).

    Let me quote the wiki here: "Open the drop down menu for Include Directories and add <blah blah>"
    The idea was that you would click on the line for "Include Directories", see the little arrow on the right side of the line, click that, click on "<Edit...>" to open up the "Include Directories" dialog box, and add "$(ProjectDir)Includes" into the (empty) box.
    Then, when you clicked OK, the line for "Include Directories" would change to say "$(ProjectDir)Includes;$(IncludePath)".
    It seems like, instead of doing that, you just typed in "$(ProjectDir)Includes" right after what was already there, without opening up that dialog box. (and same with the library directories)

    Apparently that doesn't work...(indeed, when the "Include Directories" line says "$(IncludePath);$(ProjectDir)Includes" (or whatever $(IncludePath) expands to) instead of "$(ProjectDir)Includes;$(IncludePath)", the build will fail with the errors that you got).

    The problem has to do with the fact that not only is there an http.h in the TPT source, there is also another http.h in one of the other search paths -- for me, it's in C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include.
    That means that wherever there's a #include <http> in the source code, it'll include the wrong http.h if $(ProjectDir)Includes isn't before everything else (because the preprocessor will look through the other include directories and find the wrong http.h first)

    That particular http.h (the wrong one) includes winsock2.h -- but winsock.h was already included by windows.h, which was included by bzlib.h, which was included in the same files (specifically, interface.c and main.c, where you're getting your errors) that also included the wrong http.h.
    Hence the errors that you're getting.

    In fact, if you were to rename the http.h in the TPT source to, say, httpp.h (and change the includes in interface.c, main.c, and http.c accordingly), it would compile perfectly fine (yes, I've tried it), even with $(ProjectDir)Includes after the other includes.

    So, long story short: $(ProjectDir)Includes needs to be before everything else.
    What the wiki was trying to get you to do was open up the drop-down box at the far right of the "Include Directories" line, click "<Edit...>", and add that include directory via the dialog box (then it'll get placed before everything else).
    And same with the library directories, too (just to be safe).

    I will edit the wiki to make that more clear.


    The only thing I haven't figured out yet is why you're getting this error in http.c when the wrong http.h is getting included:
    src\http.c(656): error C2371: 'http_async_req_close' : redefinition; different basic types

    Looking through the preprocessed source, I don't see any redefinition of anything in http.c...

    ...oh well, since the error goes away when you fix the other problem, I guess it doesn't really matter too much why that error's occurring, right?
  • Paudatoi
    2nd Sep 2012 Member 0 Permalink

    ah, that's where I kind of hiccuped in the wiki too. I read 'open the drop down, click on edit and then add ...' and went 'huh? there is no add, only edit, so let's try that, oh no add/edit button either' so I entered the path from the wiki, clicked 'ok' (or whatever it was) and the include path was empty except for the path entered from the wiki.

    I thought 'ohoh, from what I know, includes are important and there were a lot of include paths (presumably important for that reason) that I just deleted' and since it said 'add' in the wiki, I just did that (i.e. reopened a new project to salvage the deleted include paths and added the one from the wiki).

    Hehe, that's what happens when a programming noob tries to compile a project ;))).

    And yeah, it would be good to write in the wiki that the 'edit'-action from the dropdown deletes all the other include paths (because it said 'add', not 'replace'). That was what threw me off course.

    This src\http.c error occured to me indeed (as it was not along / in the same format as the other errors) but I just summed it up under the winsock error.

    Wow and thanks again for sorting this out!!

     

    P.S.: I did another run-through, now with the new understanding - worked fine now! xD