Menu

Error when I try to compile

Anonymous
2012-10-15
2013-05-28
  • Anonymous

    Anonymous - 2012-10-15

    Hi,
    I am using VS2010 express ( also codelite ). I got an error trying to compile a test code. This is the error I got when I compile in VS2010:

    1>---- Rebuild All started: Project: sockets, Configuration: Debug Win32 ----
    1>  sockets.cpp
    1>sockets.obj : error LNK2019: unresolved external symbol "public: __thiscall NL::Socket::~Socket(void)" (??1Socket@NL@@QAE@XZ) referenced in function _main
    1>sockets.obj : error LNK2019: unresolved external symbol "public: void __thiscall NL::Socket::send(void const *,unsigned int)" (?send@Socket@NL@@QAEXPBXI@Z) referenced in function _main
    1>sockets.obj : error LNK2019: unresolved external symbol "public: __thiscall NL::Socket::Socket(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned int,enum NL::Protocol,enum NL::IPVer)" (??0Socket@NL@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@IW4Protocol@1@W4IPVer@1@@Z) referenced in function _main
    1>sockets.obj : error LNK2019: unresolved external symbol "void __cdecl NL::init(void)" (?init@NL@@YAXXZ) referenced in function _main
    1>D:\Desarrollos\Cpp\Socket\VS\sockets\Debug\sockets.exe : fatal error LNK1120: 4 unresolved externals
    ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

    I have added ws2_32.lib but I got error

    Thanks in advance any suggestion

     
  • Pedro Francisco Pareja Ruiz

    Hello,

    Looks like you included the headers but didn't included in the project the "netlink.lib" (or whatever you named it in the static library project).

    To use the library:

    1- First create a project (static library) and include the sources of the "src" folder to compile and include "include" folder in headers path. Building it you get a lib file.
    2- Use the headers of the "include" folder in headers path and also link against the lib file you created in the previous step to use the library in your project.

    Can you confirm me if that was the cause?

     
  • Anonymous

    Anonymous - 2012-10-20

    Hi,

    Thanks for your responsde.
    Indeed, I didnt realize that I have to build a static lib first.

    Let me try, and I will tell you

     
  • Anonymous

    Anonymous - 2012-10-21

    Hi
    I have a similar problem. example (ehoserver)  is compiled with the following error:

    ||=== test_2, Debug ===|
    /home/me/workspace/test_2/netlink/socket.h|39|error: expected constructor, destructor, or type conversion before ‘class’|
    /home/me/workspace/test_2/netlink/socket.inline.h|34|error: ‘Socket’ has not been declared|
    /home/me/workspace/test_2/netlink/socket.inline.h|34|error: non-member function ‘const std::string& hostTo()’ cannot have cv-qualifier|
    /home/me/workspace/test_2/netlink/socket.inline.h||In function ‘const std::string& hostTo()’:|
    /home/me/workspace/test_2/netlink/socket.inline.h|36|error: ‘_hostTo’ was not declared in this scope|
    /home/me/workspace/test_2/netlink/socket.inline.h|45|error: ‘Socket’ has not been declared|
    /home/me/workspace/test_2/netlink/socket.inline.h|45|error: non-member function ‘const std::string& hostFrom()’ cannot have cv-qualifier|
    /home/me/workspace/test_2/netlink/socket.inline.h||In function ‘const std::string& hostFrom()’:|
    /home/me/workspace/test_2/netlink/socket.inline.h|47|error: ‘_hostFrom’ was not declared in this scope|
    /home/me/workspace/test_2/netlink/socket.inline.h|56|error: ‘Socket’ has not been declared|
    /home/me/workspace/test_2/netlink/socket.inline.h|56|error: non-member function ‘unsigned int portTo()’ cannot have cv-qualifier|
    /home/me/workspace/test_2/netlink/socket.inline.h||In function ‘unsigned int portTo()’:|
    /home/me/workspace/test_2/netlink/socket.inline.h|58|error: ‘_portTo’ was not declared in this scope|
    /home/me/workspace/test_2/netlink/socket.inline.h|67|error: ‘Socket’ has not been declared|
    /home/me/workspace/test_2/netlink/socket.inline.h|67|error: non-member function ‘unsigned int portFrom()’ cannot have cv-qualifier|
    /home/me/workspace/test_2/netlink/socket.inline.h||In function ‘unsigned int portFrom()’:|
    /home/me/workspace/test_2/netlink/socket.inline.h|69|error: ‘_portFrom’ was not declared in this scope|
    /home/me/workspace/test_2/netlink/socket.inline.h|77|error: ‘Protocol’ does not name a type|
    /home/me/workspace/test_2/netlink/socket.inline.h|87|error: ‘IPVer’ does not name a type|
    /home/me/workspace/test_2/netlink/socket.inline.h|97|error: ‘SocketType’ does not name a type|
    /home/me/workspace/test_2/netlink/socket.inline.h|110|error: ‘Socket’ has not been declared|
    /home/me/workspace/test_2/netlink/socket.inline.h|110|error: non-member function ‘unsigned int listenQueue()’ cannot have cv-qualifier|
    /home/me/workspace/test_2/netlink/socket.inline.h||In function ‘unsigned int listenQueue()’:|
    /home/me/workspace/test_2/netlink/socket.inline.h|112|error: ‘_listenQueue’ was not declared in this scope|
    /home/me/workspace/test_2/netlink/socket.inline.h|121|error: ‘Socket’ has not been declared|
    /home/me/workspace/test_2/netlink/socket.inline.h|121|error: non-member function ‘bool blocking()’ cannot have cv-qualifier|
    /home/me/workspace/test_2/netlink/socket.inline.h||In function ‘bool blocking()’:|
    /home/me/workspace/test_2/netlink/socket.inline.h|123|error: ‘_blocking’ was not declared in this scope|
    /home/me/workspace/test_2/netlink/socket.inline.h|134|error: ‘Socket’ has not been declared|
    /home/me/workspace/test_2/netlink/socket.inline.h|134|error: non-member function ‘int socketHandler()’ cannot have cv-qualifier|
    /home/me/workspace/test_2/netlink/socket.inline.h||In function ‘int socketHandler()’:|
    /home/me/workspace/test_2/netlink/socket.inline.h|136|error: ‘_socketHandler’ was not declared in this scope|
    /home/me/workspace/test_2/main.cpp|9|error: expected constructor, destructor, or type conversion before ‘int’|
    ||=== Build finished: 26 errors, 0 warnings ===|

    I program in Code :: Blocks IDE and put my archive project:

    http://depositfiles.com/rmv/8119164037975235
    that suggest?

     
  • Anonymous

    Anonymous - 2012-10-21
     
  • Pedro Francisco Pareja Ruiz

    Hello Kisly,

    I have found where the problem is. You have modified library source files: for example in socket.h commenting

    #include "netlink/core.h"

    replacing it for

    #include "socket.h"

    (I don't know why).

    I assume you have changed the includes instructions inside the sources of the library because you had problems making the compiler find them but you only have to add the include folder in the search path of the compiler to make it find them rather to modify the code of the library (as this leads to errors).

    So what I suggest you is:
    * Do not modify the source code of the library.
    * Add include folder (as it is in the library package) to the search path of the compiler (in codeblocks go to project -> build options -> search directories -> compiler -> add)

    I also would suggest you to build the library as static library instead of including all the sources files each time but this is totally up to you.

    Please let me know if this solved your problem.

    Regards.

     
  • Anonymous

    Anonymous - 2012-10-23

    Hi,

    I tried without succeed.

    I build a small console project.

    I added all files, and include "netlink include folder" in codelite search

    I got this:

    g++  -c  "D:/Desarrollos/Librerias/netlibsocket/src/socket.cc" -g -O0 -Wall  -o ./Debug/src_socket.o -I. -ID:/Desarrollos/Librerias/netlibsocket/include/ -I.
    D:/Desarrollos/Librerias/netlibsocket/src/socket.cc:39:27: error: variable or field 'freeaddrinfo' declared void
    D:/Desarrollos/Librerias/netlibsocket/src/socket.cc:39:27: error: 'PADDRINFOA' was not declared in this scope
    D:/Desarrollos/Librerias/netlibsocket/src/socket.cc: In function 'const char* NL::inet_ntop(int, const void*, char*, socklen_t)':
    D:/Desarrollos/Librerias/netlibsocket/src/socket.cc:53:49: error: 'getnameinfo' was not declared in this scope
    D:/Desarrollos/Librerias/netlibsocket/src/socket.cc:63:50: error: 'getnameinfo' was not declared in this scope
    D:/Desarrollos/Librerias/netlibsocket/src/socket.cc: In member function 'void NL::Socket::initSocket()':
    D:/Desarrollos/Librerias/netlibsocket/src/socket.cc:180:56: error: 'getaddrinfo' was not declared in this scope
    D:/Desarrollos/Librerias/netlibsocket/src/socket.cc:182:54: error: 'freeaddrinfo' was not declared in this scope
    D:/Desarrollos/Librerias/netlibsocket/src/socket.cc: In member function 'void NL::Socket::sendTo(const void*, size_t, const string&, unsigned int)':
    D:/Desarrollos/Librerias/netlibsocket/src/socket.cc:461:66: error: 'getaddrinfo' was not declared in this scope
    D:/Desarrollos/Librerias/netlibsocket/src/socket.cc:463:54: error: 'freeaddrinfo' was not declared in this scope
    mingw32-make.exe: ***  Error 1
    netlibsocket.mk:121: recipe for target `Debug/src_socket.o' failed
    mingw32-make.exe: Leaving directory `D:/Desarrollos/Librerias/netlibsocket'
    mingw32-make.exe: ***  Error 2
    netlibsocket_wsp.mk:4: recipe for target `All' failed
    -------Build Ended-------
    8 errors, 0 warnings

    Could you put a full project for download?

     
  • Pedro Francisco Pareja Ruiz

    Hi,

    As for the version 1.0.0-pre3 Mingw is not supported and the library doesn't work for this compiler.

    For windows platform is officially supported and tested Visual C++ 2008 Express Edition (you can download it for free). Any further version (as VC++ 2010) should be fine.

    The compilers supported and tested are:

    Windows: VC++ 2008+
    OSX: g++
    Linux: g++, intel compiler

    I hope this helps.
    Regards.

     

Log in to post a comment.