?
Solved

How to resolve LNK2019 unresolved external symbol errors

Posted on 2004-08-17
9
Medium Priority
?
3,264 Views
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;
#ifndef OPENSSL_NO_SHA
      unsigned char sha1_hash[SHA_DIGEST_LENGTH];
#endif
      X509_CERT_AUX *aux;
      } /* X509 */;
0
Comment
Question by:oohchild
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 24

Expert Comment

by:fridom
ID: 11827980
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.

Regards
Friedrich
0
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 300 total points
ID: 11828237
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
0
 
LVL 86

Expert Comment

by:jkr
ID: 11831032
Alternatively, add

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

to your code.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:oohchild
ID: 11837460
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?
0
 
LVL 86

Expert Comment

by:jkr
ID: 11837480
Where did you get the libs from?
0
 

Author Comment

by:oohchild
ID: 11837500
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.
0
 
LVL 86

Accepted Solution

by:
jkr earned 600 total points
ID: 11837518
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.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11838586
I agree with jkr ... Try recompiling the library from sources and then link to it
0
 

Author Comment

by:oohchild
ID: 11849172
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. :-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

770 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