I am using EVC++ and I want to compile the program which uses the sockets.
I've included
#include <winsock2.h>
And I have included in project properties a path to Ws2.lib
But still get the error at link step:
error LNK2019: unresolved external symbol WSAStartup referenced in function ...
How to resolve this problem?
#pragma comment(lib,"WS2_32")
after all #include's
You haven't linked your program with the winsock library. The Winsock 2 library is called ws2_32.lib (static) or ws2_32.dll (dynamic). It should already be on your system; you just need to tell your compiler/linker to link your program against it. The method of doing this varies by compiler, and unfortunately I'm not familiar with EVC++.
Have seen this error in codeblock IDE using MinGW.
Tried many ways but finally found this solution.
Add(your the path for MinGW installed in your system)
C:\Program Files (x86)\CodeBlocks\MinGW\lib\libws2_32
C:\Program Files (x86)\CodeBlocks\MinGW\lib\libwsock32
in codeblock IDE.
How to add:
Go to project.
build options.
Linker setting.
click add of link library.
And its done.
In my case, that problem was solved by adding
#pragma comment(lib, "ws2_32.lib")
Related
During the development of a small project using statically linked OpenSSL 1.0.2e I encountered a strange error in VS13:
Error LNK2001: unresolved external symbol _BN_is_zero
Quite often, this happens when you forget to properly liked .lib file in the project properties, but all of the properties were double-checked - they are correct.
Configuration - Release, MT, libs are MT, bh.h included.
And even if one of the libraries is not linked properly, I should have multiple compiler errors complaining about unresolved external symbols of all the elements used in the project, but in my case unresolved external symbol is the only BN_is_zero.
After quick googling there wasn't found any issues, related to openssl bugs and I guess that the problem resides at my project.
Any tips will be appreciated.
UPD
Here is some screens:
I actually forked the csrp github project and compiled it against the particular openssl libraries you are pointing at. I had to slightly modify test_srp.c and src.c to add some code that isn't available on VS2013. A fork of csrp with the changes applied and the visual studio project for VS2013 to compile it can be found here:
https://github.com/sigmoidal/csrp
Note that you need to change the paths of the openssl path on BOTH the debug and release versions to reflect your VS Configuration Properties:
C/C++ > General > Additional Include Directories
D:\dev\openssl\openssl-1.0.2e-vs2013\include
(you should not point it to $openssl_path/include/openssl, it will not work)
and also:
Linker > Input > Additional Dependencies:
For release configuration:
D:\dev\openssl\openssl-1.0.2e-vs2013\lib\libeay32MT.lib
D:\dev\openssl\openssl-1.0.2e-vs2013\lib\ssleay32MT.lib
For debug configuration:
D:\dev\openssl\openssl-1.0.2e-vs2013\lib\libeay32MTd.lib
D:\dev\openssl\openssl-1.0.2e-vs2013\lib\ssleay32MTd.lib
(notice the "d" suffix on debug libs)
Compiled ok for me.
I'm guessing here, but according to the OpenSSL source BN_is_zero is defined as a macro:
http://osxr.org/openssl/source/crypto/bn/bn.h#0407
So perhaps the module that is compiled into srp.obj is making a call to BN_is_zero but is not including bn/bn.h and in the absence of a prototype the compiler is generating a default one.
If this is the case, including the bn.h definitions should avoid the linker error.
It was tricky, but I've finally solved it based on the Drew MacInnis tips.
The matter is that openssl 1.0.2e broke the BN_is_zero functionality by simply removing the macros-containing header from sources. So, the solution is:
Download the bn.h include file from 1.0.1h (or here)
Place bn.h to %OPENSSL_HOME%/crypto/bn directory
Change #include <openssl/bn.h> for #include <../crypto/bn/bn.h>
I am trying to build an appliction based upon the pcredemo application. When I try and compile the application in Windows I get the following compiler errors.
undefined reference to `_imp__pcre_compile'|
undefined reference to `_imp__pcre_exec'|
undefined reference to `_imp__pcre_free'|
Am I missing some .dll files or something?
Those are linker errors. You need to make sure that you are passing the PCRE .lib files to the linker. Another possible problem could be that your compiler/linker is using a different .lib file format from that used to build the PCRE .lib files.
If you are linking PCRE statically, you need to #define PCRE_STATIC before compiling.
I am writing my program in Visual Studio 2010.
I am unable to link a file named ws2_32.dll with my project.
Can anyone tell me how I can do that?
Typically you dont link to ws2_32.dll directly but to WS2_32.Lib, which you can find in the Windows SDK. So in your code you write
#include <winsock2.h>
and to your linker-settings you add WS2_32.Lib and you're good to go.
The Windows SDK is here:
http://msdn.microsoft.com/en-us/windows/bb980924.aspx
The first order of business is importing the header file that defines functions exported by ws2_32.dll. You do that by adding the following statement to the top of any source file that you wish to call those functions in:
#include <winsock2.h>
Then, you have to tell the linker where it can find the import library for that DLL. There are two ways to do that in Visual Studio, but the simplest way is adding the following line to your source code:
#pragma comment(lib, "ws2_32.lib")
You could also add it as a dependency to your linker's "Additional Dependencies" property (find that under your Project Properties -> Configuration Properties -> Linker -> Input).
MSDN also has a getting started guide that walks you through creating a basic Winsock application. Make sure that you've read it before proceeding any further.
You need to load the file using LoadLibrary if you do not have the lib file.
I have installed OpenCV C libraries from package management into my Kubuntu 9.10. I wrote a small image modification program that uses those libraries, but I can't compile it, because every time I try to compile I get the error message that the functions from OpenCV library cannot be found.
Those header files are in folder /usr/include/opencv/ but still the compiler says that functions cannot be found.
I have tried to include them by basic
#include <highgui.h>
#include <cv.h>
commands in netbeans (and I have set netbeans to search header files from that specific directory) and also tried to include them with full path.
#include </usr/include/opencv/highgui.h>
#include </usr/include/opencv/cv.h>
Also I tried to compile my source file in console (with full path includes), but again I got the same error message that the functions from those libraries cannot be found.
Edit:
The error message that I get is
undefined reference to 'function_name'
I get that error for every function that I try to use from that opencv library.
Any idea how to fix that problem?
Edit II:
in case someone else is using netbeans 6.7.1 and has the same problem, here's the solution copy pasted from another website:
Here I presume that you have succesfully installed the opencv library either manually or via package management.
Open Netbeans then do the following:
Select Tools -> Options -> C/C++ -> Code Assistance -> add Include Directories
(For me, /usr/local/include/opencv)
Create new project, then:
Right click on Project Name -> Properties ->Build -> C/C++ Compiler -> Include Directories
Include Directories : /usr/local/include/opencv
Right click on Project Name -> Properties -> Build -> linker ->
Include Directories : /usr/local/include/opencv
Additional Options : -I/usr/local/include/opencv -L/usr/local/lib -lcxcore -lcv -lhighgui -lcvaux -lml
Then writing program and compile!!
"undefined reference to" is a linker error. You forgot to link your application against the OpenCV libraries. Make sure you link against cv and highgui (-lcv -lhighgui) or use the pkg-config call that Tobu provided. I'd also second the request for more detailed error messages.
OpenCV uses pkg-config, the standard way to locate libraries and headers on unix. You can run (untested):
make CFLAGS="$(pkg-config --cflags --libs opencv)" your-program
how can i resolve a linker error in c?
this is the error message:
undefined reference to HPDF_Page_SetRGBStroke
If you are using an external library, you have to tell the linker that it should be included. It has no means of automagically finding out what you're using there.
Using gcc you can do this by compiling the program with -llibrary.
Apparently, you're trying to use a routine from the libharu PDF library, and it seems you're not linking against this library.
How exactly you would resolve this depends on the toolchain you're using -- under gcc, you would have to add a -lharu option or similar to the linker options.