Monday, May 24, 2010

How do I link a file in dev c?

I am trying to get a program working that uses sockets. I have included winsock2.h, and everything compiles fine. However, I am getting linker errors "undefined reference to...". After googling, it would appear that this is caused by a dll not being linked, and so I assume I should link the ws2_32.dll. I do not know how to do this. Please help me :)

How do I link a file in dev c?
How to link: Generally, for all the functions available in the mingw header files, the mingw package provides libraries with the function definitions; not all available libraries are automatically linked, because not all functions are standard C/C++; you just have to link them to your project when you need them.


The library files are called "libname.a" and are located in the Dev-Cpp\lib folder; the easiest way to link them is to add -lname (note: no "lib" and no ".a", and that's a small L not a capital i) to the linker parameters in your project, that is Project Options - Parameters - Linker


You can also use the Add Library or Object button in that window, and that's ok for object files, but for libraries you may run into problems when you move things to other folders or to another computer.


If you use external libraries (i.e. not included in mingw), then you should either put them in the Dev-Cpp\lib folder, or add the folder which contains the libraries to the list of library dirs, in Project Options - Directories - Library Directories.


You may still have problems if the libraries you link were compiled with an old version of gcc (and definitely if they were compiled with another compiler). Try to get libraries that match your compiler, or recompile them if you have the source code.


Finding libraries: Which library do you need to link? Usually, the library name is similar to the name of the header file that declares the functions, e.g. wingdi.h -%26gt; libgdi32.a, winsock2.h -%26gt; libws2_32.a; if you can't find it then just do a file search using Windows Explorer (search for library files (lib*.a) containing the function name).





This text was taken off from:


http://aditsu.freeunixhost.com/dev-cpp-f...


No comments:

Post a Comment