Menu

Linker Problem

tweenki
2007-12-27
2012-09-26
  • tweenki

    tweenki - 2007-12-27

    i use the newest version under vista.

    my source code looks so:

    include <windows.h>

    include <winsock2.h>

    include <iostream.h>

    using namespace std;

    int startWinsock()
    {
    WSADATA wsa;
    return WSAStartup(MAKEWORD(2,0),&wsa);
    }

    int main()
    {

    long rc;

    rc=startWinsock();

    if(rc!=0)

    {

    cout&lt;&lt;&quot;Fehler: startWinsock, fehler code: &quot;&lt;&lt;rc&lt;&lt;&quot;\n&quot;;
    
    return 1;
    

    }

    else

    {

    cout&lt;&lt;&quot;Winsock gestartet!\n&quot;;
    

    }

    return 0;

    }

    and this is my compiler log:

    Compiler: Default compiler
    Building Makefile: "B:\Programing\Socket\Makefile.win"
    Führt make... aus
    make.exe -f "B:\Programing\Socket\Makefile.win" all
    g++.exe socket.o -o "Socket.exe" -L"E:/Dev-Cpp/lib" -L"E:/Dev-Cpp/lib" -llibwsock32 -llibws2_32 -L"E:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"

    E:\Dev-Cpp\Bin..\lib\gcc\mingw32\3.4.2........\mingw32\bin\ld.exe: cannot find -llibwsock32
    collect2: ld returned 1 exit status

    make.exe: *** [Socket.exe] Error 1

    Ausführung beendet

    i included this libwsock libraries. but something is wrong.

    thanks for help.

     
    • tweenki

      tweenki - 2007-12-29

      so this libraries are dll toos? what dlls are i know.

       
      • cpns

        cpns - 2007-12-29

        A library may be either statically linked or dynamically linked. DLLs normally have an associated 'export library' to allow you to link to them. When you for example link libws2_32.a, this is an export library for ws2_32.dll which is part of the operating system.

        Not all library files are export libraries for DLLs some are simply static libraries.

        Clifford

         
    • Wayne Keen

      Wayne Keen - 2007-12-27

      When you have a library in a filename

      libxyz.a

      you link it as follows:

      -lxyz

      There is a section in the "Please Read" thread on the compile log,
      including headers, and linking libraries that goes into this process
      in greater detail.

      Wayne

       
    • cpns

      cpns - 2007-12-28

      The difference between typing "latest" and typing the actual number is minimal, but the latter is far more useful. We just have to trust that you know what the 'latest' is!?

       
    • tweenki

      tweenki - 2007-12-28

      thanks very much.

      naother question why comes sometimes this warning:

      warning This file includes at least one deprecated or antiquated header. \

      Please consider using one of the 32 headers found in section 17.4.1.2 of the \ C++ standard. Examples include substituting the <X> header for the <X.h> \ header for C++ includes, or <iostream> instead of the deprecated header \ <iostream.h>. To disable this warning use -Wno-deprecated.

      and sometimes not. but i don´t change something on code?

       
      • Wayne Keen

        Wayne Keen - 2007-12-28

        You are using headers with names such as iostream.h.

        This notation has been deprecated (which means it is old and no longer
        technically correct) for almost 10 years, since the ANSI standard for
        the language first came out.

        Take a look at the example "Hello World" that is given in the thread
        titled "Please Read Before Posting Question" to see an example of how
        the correct header notation can be applied.

        Wayne

         
    • cpns

      cpns - 2007-12-28

      The answer to your question is given in the warning message itself! Read it!

      The reason you get it sometimes and not others is because being 'only' a warning, the code gets compiled in any case. If you don't change the code you will not see the warning because because unchanged source modules do not get unnecessarily recompiled.

      If you use the -Werror option, all warnings are regarded as errors and compilation will fail - so you will get it every time.

      Clifford

       
    • tweenki

      tweenki - 2007-12-28

      but this is only at iostream, isnt it?

      another question what are this libraries which i link. why isnt that in the header files? how do i build myself such files?

       
    • cpns

      cpns - 2007-12-29

      >> but this is only at iostream, isnt it?

      Uh? What does that mean. As the message says "consider using one of the 32 headers found in section 17.4.1.2 of the
      C++ standard". There are therefore 32 standard headers.

      >> what are this libraries which i link.
      Libraries (or archives) are collections of previously compiled object code that can be extracted and linked you your application.

      >> why isnt that in the header files?
      Header files are generally only declarative, not instantiative. One exception is the use of inline code). #include is merely a pre-processor text insertion, the code in the header becomes part of that module, if the code were instantiative, and you included it in multiple separately compiled modules, when you linked that code you would end up with multiple copies of the code.

      >> how do i build myself such files?
      File->New->Project, then select either Static Library or DLL.

      See also: http://sourceforge.net/forum/message.php?msg_id=2670009 and http://www.cs.bu.edu/teaching/c/separate-compilation/

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.