How to resolve LNK2019 unresolved external symbol errors

Posted on 2004-08-17
Last Modified: 2012-06-22
I am using OpenSSL libraries in my C program, the IDE environment is Visual Studio .NET

The following is my sample codes:
#include <openssl/x509.h>
#include <openssl/ssl.h>
unsigned char      *p= (unsigned char *)myattr;
FILE *crtfile;
int i;
X509 *x;

crtfile = fopen("crtfile.txt", "w");
i = fwrite(p, 1, sizeof(p),crtfile);
x = d2i_X509_fp(crtfile, NULL);

This on compilation generates the following error:
error LNK2019: unresolved external symbol _d2i_X509_fp referenced in function _DisplayObjectInfo

d2i_x509_fp is a third party library function which is declared as follows:
X509 *d2i_X509_fp(FILE *fp, X509 **x509);

typedef x509_st X509;
struct x509_st
      X509_CINF *cert_info;
      X509_ALGOR *sig_alg;
      ASN1_BIT_STRING *signature;
      int valid;
      int references;
      char *name;
      CRYPTO_EX_DATA ex_data;
      /* These contain copies of various extension values */
      long ex_pathlen;
      unsigned long ex_flags;
      unsigned long ex_kusage;
      unsigned long ex_xkusage;
      unsigned long ex_nscert;
      ASN1_OCTET_STRING *skid;
      struct AUTHORITY_KEYID_st *akid;
      unsigned char sha1_hash[SHA_DIGEST_LENGTH];
      X509_CERT_AUX *aux;
      } /* X509 */;
Question by:oohchild
  • 3
  • 3
  • 2
  • +1
LVL 24

Expert Comment

Comment Utility
you have to link against the proper libraries. That is here the library which contains d2i_x509_fp, you should ask the developer of it.

LVL 45

Assisted Solution

sunnycoder earned 100 total points
Comment Utility
tools->options->directories tab

select library files from the drop down box

click add (the broken lines rectangle icon)
add path to SSL library and recompile your program
LVL 86

Expert Comment

Comment Utility
Alternatively, add

#pragma comment ( lib, "openssl.lib")

to your code.

Author Comment

Comment Utility
I tried explicitly linking to the libraries, this time round it complains

fatal error LNK1136: invalid or corrupt file

Does it mean the libraries is corrupted?
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

LVL 86

Expert Comment

Comment Utility
Where did you get the libs from?

Author Comment

Comment Utility
I forgot which site I download it - it is openssl v0.9.7c GNUWin32, maybe i will link with an earlier version (0.9.6) and check if the same problem exists.
LVL 86

Accepted Solution

jkr earned 200 total points
Comment Utility
So, I assume the .lib format is not compatible (no standards here, *sigh*) - but, you could try to compile this one on your own, since I suppose the source code is available.
LVL 45

Expert Comment

Comment Utility
I agree with jkr ... Try recompiling the library from sources and then link to it

Author Comment

Comment Utility
I found the source of the error, the openssl library is compiled using the GnuWin32 compiler and for some reason is not compatible. After recompiling the source with nmake, it works okay. Thanks for the help. :-)

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now