[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

LNK2019 error when I added .c files to my cpp project in VS 2005.

Posted on 2006-06-02
5
Medium Priority
?
589 Views
Last Modified: 2008-02-01
Hi, I'm working on a COM application using the C++ compiler in VS2005 on
Win2K server.  Most of the code files are in cpp but I've just added a few C
file for BER encoding to my C++ proejct.  Now I got a dozen of LNK2019 errors
when I try to compile my proejct.  Can someone have a look and let me know
how I can correct this problem?  I've added both the .h files and the .c
files to my proejct and don't know why it .  can't resolve the external
symbobls.


error LNK2019: unresolved external symbol "void __cdecl DebugLogger(int,char
*,char const * const,int,int,char *,...)" (?DebugLogger@@YAXHPADQBDHH0ZZ)
referenced in function "public: void __thiscall
CGroupPage::DecodeAsnGroup(struct Blob *,class CGroupContextData *)"
(?DecodeAsnGroup@CGroupPage@@QAEXPAUBlob@@PAVCGroupContextData@@@Z)      CGroupPage.obj
error LNK2019: unresolved external symbol "void __cdecl AsnFree(struct
AsnData *)" (?AsnFree@@YAXPAUAsnData@@@Z) referenced in function "public:
void __thiscall CGroupPage::DecodeAsnGroup(struct Blob *,class
CGroupContextData *)"
(?DecodeAsnGroup@CGroupPage@@QAEXPAUBlob@@PAVCGroupContextData@@@Z)      CGroupPage.obj
error LNK2019: unresolved external symbol "struct Blob * __cdecl
AsnExtractData(struct AsnData *)"
(?AsnExtractData@@YAPAUBlob@@PAUAsnData@@@Z) referenced in function "public:
void __thiscall CGroupPage::EncodeAsnGroup(class std::_Vector_iterator<class
CGroupContextData,class std::allocator<class CGroupContextData> >,struct Blob
* *)"
(?EncodeAsnGroup@CGroupPage@@QAEXV?$_Vector_iterator@VCGroupContextData@@V?$allocator@VCGroupContextData@@@std@@@std@@PAPAUBlob@@@Z)      CGroupPage.obj
error LNK2019: unresolved external symbol "struct AsnData * __cdecl
AsnAlloc(struct Blob *)" (?AsnAlloc@@YAPAUAsnData@@PAUBlob@@@Z) referenced in
function "public: void __thiscall CGroupPage::DecodeAsnGroup(struct Blob
*,class CGroupContextData *)"
(?DecodeAsnGroup@CGroupPage@@QAEXPAUBlob@@PAVCGroupContextData@@@Z)      CGroupPage.obj
error LNK2019: unresolved external symbol "enum Bool __cdecl
AsnWriteInteger(struct AsnData *,int)"
(?AsnWriteInteger@@YA?AW4Bool@@PAUAsnData@@H@Z) referenced in function
"public: void __thiscall CGroupPage::EncodeAsnGroup(class
std::_Vector_iterator<class CGroupContextData,class std::allocator<class
CGroupContextData> >,struct Blob * *)"
(?EncodeAsnGroup@CGroupPage@@QAEXV?$_Vector_iterator@VCGroupContextData@@V?$allocator@VCGroupContextData@@@std@@@std@@PAPAUBlob@@@Z)      CGroupPage.obj
error LNK2019: unresolved external symbol "enum Bool __cdecl
AsnWriteGeneralString(struct AsnData *,char const *)"
(?AsnWriteGeneralString@@YA?AW4Bool@@PAUAsnData@@PBD@Z) referenced in
function "public: void __thiscall CGroupPage::EncodeAsnGroup(class
std::_Vector_iterator<class CGroupContextData,class std::allocator<class
CGroupContextData> >,struct Blob * *)"
(?EncodeAsnGroup@CGroupPage@@QAEXV?$_Vector_iterator@VCGroupContextData@@V?$allocator@VCGroupContextData@@@std@@@std@@PAPAUBlob@@@Z)      CGroupPage.obj
error LNK2019: unresolved external symbol "enum Bool __cdecl
AsnReadInteger(struct AsnData *,int *)"
(?AsnReadInteger@@YA?AW4Bool@@PAUAsnData@@PAH@Z) referenced in function
"public: void __thiscall CGroupPage::DecodeAsnGroup(struct Blob *,class
CGroupContextData *)"
(?DecodeAsnGroup@CGroupPage@@QAEXPAUBlob@@PAVCGroupContextData@@@Z)      CGroupPage.obj
error LNK2019: unresolved external symbol "enum Bool __cdecl
AsnReadGeneralString(struct AsnData *,char * *)"
(?AsnReadGeneralString@@YA?AW4Bool@@PAUAsnData@@PAPAD@Z) referenced in
function "public: void __thiscall CGroupPage::DecodeAsnGroup(struct Blob
*,class CGroupContextData *)"
(?DecodeAsnGroup@CGroupPage@@QAEXPAUBlob@@PAVCGroupContextData@@@Z)      CGroupPage.obj
error LNK2019: unresolved external symbol "enum Bool __cdecl
AsnPushTag(struct AsnData *,enum ASN_TAG)"
(?AsnPushTag@@YA?AW4Bool@@PAUAsnData@@W4ASN_TAG@@@Z) referenced in function
"public: void __thiscall CGroupPage::EncodeAsnGroup(class
std::_Vector_iterator<class CGroupContextData,class std::allocator<class
CGroupContextData> >,struct Blob * *)"
(?EncodeAsnGroup@CGroupPage@@QAEXV?$_Vector_iterator@VCGroupContextData@@V?$allocator@VCGroupContextData@@@std@@@std@@PAPAUBlob@@@Z)      CGroupPage.obj
error LNK2019: unresolved external symbol "enum Bool __cdecl
AsnPopTag(struct AsnData *)" (?AsnPopTag@@YA?AW4Bool@@PAUAsnData@@@Z)
referenced in function "public: void __thiscall
CGroupPage::EncodeAsnGroup(class std::_Vector_iterator<class
CGroupContextData,class std::allocator<class CGroupContextData> >,struct Blob
* *)"
(?EncodeAsnGroup@CGroupPage@@QAEXV?$_Vector_iterator@VCGroupContextData@@V?$allocator@VCGroupContextData@@@std@@@std@@PAPAUBlob@@@Z)      CGroupPage.obj
error LNK2019: unresolved external symbol "enum Bool __cdecl
AsnEndReadTag(struct AsnData *)" (?AsnEndReadTag@@YA?AW4Bool@@PAUAsnData@@@Z)
referenced in function "public: void __thiscall
CGroupPage::DecodeAsnGroup(struct Blob *,class CGroupContextData *)"
(?DecodeAsnGroup@CGroupPage@@QAEXPAUBlob@@PAVCGroupContextData@@@Z)      CGroupPage.obj
error LNK2019: unresolved external symbol "enum Bool __cdecl
AsnBeginReadTag(struct AsnData *,unsigned char)"
(?AsnBeginReadTag@@YA?AW4Bool@@PAUAsnData@@E@Z) referenced in function
"public: void __thiscall CGroupPage::DecodeAsnGroup(struct Blob *,class
CGroupContextData *)"
(?DecodeAsnGroup@CGroupPage@@QAEXPAUBlob@@PAVCGroupContextData@@@Z)      CGroupPage.obj


//---------------one of the .h file that goes with the .c file
/* As of 1999 ISO C standard - macros support variable arguments */
#define DbgLog(l, m, ...) DebugLogger((l), __FILE__, (const char*)
__FUNCTION__, __LINE__, 0, (m), ## __VA_ARGS__)

/* Same as above and include the unix error number and description */
#define DbgLogErr(l, e, m, ...) DebugLogger((l), __FILE__, (const char*)
__FUNCTION__, __LINE__, (e), (m), ## __VA_ARGS__)

typedef enum
{
      DL_ERROR,
      DL_WARNING,
      DL_SUCCESS,
      DL_PEDANTIC
} DEBUG_LEVEL;

typedef enum
{
      DE_SUCCESS,
      DE_CONNECTION_LOST,
      DE_UNKNOWN_REQUEST,
      DE_UNKNOWN_LIBRARY,
      DE_UNKNOWN_MSG_VERSION,
      DE_MSG_SEQ_ERROR,
      DE_MEMORY_ALLOCATION_FAILURE,
      DE_ENCODE_MESSAGE_PACKET_FAILURE,
      DE_EXTRACT_MESSAGE_FAILURE,
      DE_SELECT_FAILURE,
      DE_SEND_PACKET_FAILURE,
      DE_BAD_SOCKET,
      DE_RECEIVE_PACKET_FAILURE,
      DE_TRUNCATED_LENGTH_RECEIVED,
      DE_SOCKET_FAILURE,
      DE_FIFO_EMPTY,
      DE_RESPONSE_TIMEOUT,
      DE_LOAD_LIBRARY_FAILURE,
      DE_THREAD_CREATION_FAILURE,
      DE_NULL_SERVER_FUNCTION_TABLE,
      DE_NULL_CLIENT_FUNCTION_TABLE,
      DE_REASSIGNING_CLIENT_FUNCTION_TABLE,
      DE_FIFO_CONDITION_WAIT_FAILURE,
      DE_FIFO_TAIL_IS_NULL_ON_FETCH,
      DE_SIGNAL_THREAD_FAILURE,
      DE_BAD_ARGUMENTS,
      DE_BUFFER_EXHAUSTED,
      DE_RWLOCK_INITIALIZATION_FAILURE,
      DE_WRITE_LOCK_FAILURE,
      DE_READ_LOCK_FAILURE,
      DE_RELEASE_LOCK_FAILURE,
      DE_MUTEX_INITIALIZATION_FAILURE,
      DE_INDEX_INSERT_FAILURE,
      DE_INVALID_ENTRY_TYPE,
      DE_WAITING_CONDITION_FAILURE,
      DE_UNABLE_TO_ACQUIRE_ADS_CONNECTION,
      DE_ROW_INSERT_FAILURE,
      DE_UPDATE_MESSAGE_POST_FAILURE,
      DE_MUTEX_LOCK_FAILURE,
      DE_MUTEX_UNLOCK_FAILURE,
      DE_UNABLE_TO_CREATE_TEMPORARY_ROW,
      DE_UNABLE_TO_GET_USER_LIST_FROM_AD,
      DE_UNABLE_TO_GET_GROUP_LIST_FROM_AD,
      DE_UNABLE_TO_OPEN_CONFIGURATION_FILE
} DE_ERRORS;

--
Thanks.
0
Comment
Question by:lapucca
  • 3
5 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 16819500
Where is DebugLogger function defined?
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 2000 total points
ID: 16819728
There might be a very simple sollution:

1) Remove each of the (new) .C source files from your project
2) Rename each of these .C files to have an extension of .CPP
3) Add the files (with the new .CPP extension) back to the project and do a Clean and a full Build

In some cases, that should change the "name-mangling" and function signatures to match and avoid the linker errors.  There are several situations where this won't help, but because it is so simple to do, it is worth a try.

Report back with the results.  If that does not work, we can try some alternate options.

-- Dan
0
 

Author Comment

by:lapucca
ID: 16820163
I did what you suggested by renaming all the c files to cpp but I'm still getting the same LNK2091 error.  Below is the code for DebugLogger.  I appreciate any help or other suggestions you have.  Thank you.

DebugLogger(int nLevel, char *szFile, const char pszFunction[], int nLine, int nError, char *szMessage, ...)
{
      va_list            args;
      //char                  acDateTime[ 20 ];
      
      if ( !DebugActive( nLevel ) )
            return;
            
      //pthread_mutex_lock( &g_OutputMutex );
      
      va_start(args, szMessage);
      
      if ( strncmp( szFile, "../", 3 ) == 0 )
            szFile += 3;
            
      //GetDateTimeStamp( acDateTime, sizeof(acDateTime) );
      //fprintf( stderr, "%s [%ld:%-10s] %s,%d:%s: ",
      //      acDateTime,
      //      (long) getpid(),
      //      debugThreadGetName( pthread_self() ),
      //      szFile,
      //      nLine,
      //      pszFunction );
      //vfprintf( stderr, szMessage, args );
      //fputs( "\n", stderr );

      /* only display error number and text when nError is non-zero */
      if ( nError )
      {
            /* The strerror_r() function does not work on RHAS4.
             * We fall back to using strerror with the hope that
             * multiple threads will not collide when reporting
             * debugging messages.
             */

#            ifdef HAVE_STRERROR_R
#                  define             ERROR_BUFFER_SIZE 512
                  char                  acError[ ERROR_BUFFER_SIZE ];

                  acError[0] = '\0';
                  strerror_r( nError, (char*) acError, ERROR_BUFFER_SIZE - 1 );
                  fprintf( stderr, "errno=%d (%s)\n",
                        nError,
                        (char*) acError );
#            else
                  fprintf( stderr, "errno=%d (%s)\n",
                        nError,
                        (char*) strerror( nError ) );
#            endif
      }
            
      va_end(args);

      //pthread_mutex_unlock( &g_OutputMutex );

      return;
}
0
 

Author Comment

by:lapucca
ID: 16820230
Oh, wait.  I didn't do the clean and rebuild bit last time.  I just did that and the lnk2019 error is gone.  I think it might worked.  Let me test it out some more and let you know.  Thank you
0
 

Author Comment

by:lapucca
ID: 16820257
Ok, I think that got rid of the LNK errors.  I'm getting other errors but no LNK2019.  Thank you very much.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

873 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