Thread: Need help with LNK error

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    8

    Need help with LNK error

    Hi, when I build my project I got the following errors:

    main3.obj : error LNK2031: unable to generate p/invoke for "extern "C" unsigned char * __clrcall SHA1(unsigned char const *,unsigned int,unsigned char *)" (?SHA1@@$$J0YMPAEPBEIPAE@Z); calling convention missing in metadata
    main3.obj : error LNK2028: unresolved token (0A000012) "extern "C" unsigned char * __clrcall SHA1(unsigned char const *,unsigned int,unsigned char *)" (?SHA1@@$$J0YMPAEPBEIPAE@Z) referenced in function "int __clrcall openssl(unsigned long,unsigned long)" (?openssl@@$$FYMHKK@Z)
    main3.obj : error LNK2019: unresolved external symbol "extern "C" unsigned char * __clrcall SHA1(unsigned char const *,unsigned int,unsigned char *)" (?SHA1@@$$J0YMPAEPBEIPAE@Z) referenced in function "int __clrcall openssl(unsigned long,unsigned long)" (?openssl@@$$FYMHKK@Z)
    E:\VHDL_work\communication\Communication_Control_P anel\Debug\Communication_Control_Panel.exe : fatal error LNK1120: 2 unresolved externals

    I have already set Linker input option correct, so I can't see where those errors are coming from, can someone help me or give a point ?
    MS Visual studio C++ 2005

  2. #2
    Registered User UltraKing227's Avatar
    Join Date
    Jan 2010
    Location
    USA, New york
    Posts
    123
    what can i do with just the errors. show atleast the
    source-code so i can point to the problem. :S

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    8

    Thumbs up Thank you for reply

    Thank you for reply
    My code is pretty long so I'm not sure of uploading it, I guess I could upload a part of it, where I think cause the error.
    Code:
    #include "stdafx.h"
    #include "openssl/sha.h"
    #include <stdio.h>
    #include <stdlib.h> /* required for randomize() and random() */
    #include <time.h>  /* required for time()*/
    #include <math.h>
    #include <fcntl.h>
    #include <string.h>
    #include "unistd.h"
    #include "function.h"
    
    #pragma once
    
    #define Q 60
    #define D 8
    
    unsigned long B;
    unsigned long ** key;
    
    unsigned long rounds;
    unsigned long rest;
    unsigned long a,i,j,k,l,r;
    int fd;
    int RUSAGE_SELF;
    
    int openssl(unsigned long rounds, unsigned long B ) 
    {
    	unsigned char key[][32]= {""};//use to store all the 256-bit keys ,key[B][32] 8*32
    	unsigned char message[48];	//the first 64 bit of message stands for N, 
    								//and 2nd 64 bits stands for R and the rest stands for key. 
    	//definition de msg
    
    	unsigned char result[21]; 
    	unsigned char result_temp[22];
    
    	srand((unsigned) time(NULL));
    
    	for(r=0;r<rounds;r++)
    	{
    		fd = _open( "/dev/urandom", O_RDONLY );
    		_read( fd, (void *) key, B*32 );//2^16*16*2
    		_read(fd, (void *)message, 16);//64*2
    		_close(fd);
    
    		rand_1=rand() /64 %256;
    		rand_2=rand() /64 %256;
    		ID = rand_1+rand_2*256;
    
    		ID = ID%B;//in case ID >B
    
    		memcpy(message+16, key[ID],32);
    		SHA1(message,48,result);//instead of Ff fct
    
                    B=64;
    		for (i=0; i <B; i++)
    		{
    			memcpy(message+16, key[i],32);
    			SHA1(message,48,result_temp);
    
    			for(j=0; j<20; j++)
    			{
    				if(result_temp[j]!=result[j]) 
    				{
    					break;
    				}	
    			}		
    			if (j==20)
    			{	
    				break;
    			}	
    		}
    
    	}//end of rounds
    
    	return 0;
    }

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > I have already set Linker input option correct
    Well apparently you haven't.

    Or at least not to the satisfaction of the linker.

    Did you specify both the name of the library AND the location where to find it?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  5. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM