Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts

    including winsock library without an ide

    im trying to make a client-server application using winsock in c++ on a windows tcp socket but everywhere i look (for example http://www.hal-pc.org/~johnnie2/winsock.html) it tells me to set my ide to use some lib file (i think one place told me it was a dll file)

    "Remember that any code presented in this tutorial should be linked with the Winsock library, usually wsock32.lib or something similarly named."

    i have devC++ but im trying to get this to work from notepad so that i can compile using mingw or borland compiler from command line, is there any way i can get this to work, in the example from the site linked above there is the line "ObjFile=C:\Dev-C++\Lib\libws2_32.a" in a .dev file and on the msdn site it says "The WSAStartup function is called to initiate use of WS2_32.lib" but i cant find anywhere to tell me how to use this file out of devC++ (and how do i know what hte file is actually called since there are at least 3 possible names for it)
    Last edited by ghell; 10-28-2004 at 08:36 PM.

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok the easiest way to compile a program from the command line is by using a makefile. If you haven't done so, you should create one for your project. Something like this goes in your makefile (simplified)...


    # tell the linker where to find the winsock library
    LIBS = -L"D:/Dev-Cpp/lib" ../../lib/libws2_32.a -g3


    # after compiling, link with winsock library
    g++ my_object.o -o my_exe.exe $(LIBS)

  • #3
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    ive been havin a go at this but i dont really know what a makefile is/does

    how do i make a makefile (if i can do it in notepad whats the non simplified version)

    and how do i run it once its made

  • #4
    Regular Coder
    Join Date
    Oct 2004
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes you can make all the files you need from notepad. You should check out some tutorials on using gcc and make utilities, and also very important is reading the documentation. You can find all you ever wanted to know about 'make' here: GNU Make Utility.

    I've gone ahead and made a simple makefile for you that builds the tutorial you posted a link to, but you should still read the documentation to find out why it works.

    Place this in a plain text file, named "makefile", and place it in the directory with your project files. You may have to change some paths to get it to work for you, such as changing D:/ to C:/, then follow the directions under "Running this file".

    Code:
    # Sample Makefile for command line compilation
    #
    # this makefile demonstrates how to compile
    # a simple program with the Dev-C 'make' utility, 
    # while linking with the winsock library
    #
    # we could do this without a makefile, by
    # instead typing these commands on the
    # command line, but using a makefile makes 
    # life easier by letting the 'make' utility
    # execute these commands for us
    
    
    
    ######### running this file:
    
    # from the command line cd to your project directory
    # ex: shell> cd D:\Dev-Cpp\Projects\Winsock
    # invoke 'make' on this file:
    # ex: shell> D:\Dev-Cpp\bin\make.exe
    # or if your makefile is named something else:
    # ex: shell> D:\Dev-Cpp\bin\make.exe -f myMakefile
    
    
    
    
    ######### set some variables we'll need 
    
    # tell the linker where to find the standard libs and the winsock libs
    LIBS = -L"D:/Dev-Cpp/lib" ../../lib/libws2_32.a
    
    # normally from a shell 'make' and 'gcc' can be
    # called from anywhere, but since Dev-C tools by default
    # aren't installed as shell programs, we'll need to tell
    # the OS where these are located
    # NOTE: gcc.exe is the 'C' compiler, g++.exe is the 'C++' compiler
    G++ = D:\Dev-Cpp\bin\g++.exe
    
    # these are the files we want to compile
    SOURCES = main.cpp
    
    # these are the objects we want to create and link
    OBJECTS = main.o
    
    # this is the binary we want to build
    BINARY = main.exe
    
    # this is any compiler flags we would like
    # ex: -g for debug build
    CFLAGS =
    
    # this is any linker flags we would like
    LFLAGS =
    
    
    
    
    ######### here's where make starts processing commands
    
    all:	build
    
    # we can call 'make clean' to remove files created
    clean:
    	rm -f *.o $(BINARY)
    
    
    
    ######### compile our files
    
    # this line tells the compiler to create
    # object files from our source files
    $(OBJECTS):
    	$(G++) -c $(SOURCES) -o $(OBJECTS) $(CFLAGS)
    
    
    
    ######### link our program
    
    # this line first calls the compile line above,
    # then tells the linker to create an exe from our
    # object files, while linking with the winsock library
    build: $(OBJECTS)
    	$(G++) -o $(BINARY) $(OBJECTS) $(LIBS) $(LFLAGS)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •