|
-
April 20th, 2010, 05:41 AM
#1
[SOLVED] unresolved external symbol "int __cdecl _.." between C and Cpp file
Hi all, I am receiving a
"error LNK2019: unresolved external symbol "int __cdecl _function(...)" error while trying to compile the following files:
main.cpp
--------------------------------------------
#include "function.h"
int main()
{
function(0, 0);
return 0;
}
---------------------------------------------
function.h
--------------------------------------------
#ifndef FNC_H
#define FNC_H
extern void function(int a, int b);
#endif
---------------------------------------------
function.c
--------------------------------------------
#include "function.h"
void function(int a, int b);
{
// do something here
}
---------------------------------------------
Seems like the program cannot find the function's definition. Why is that?
Am I missing something with the association .h -> .c ?
Please give me suggestions
Last edited by leKoxn; April 20th, 2010 at 02:20 PM.
Reason: problem solved
-
April 20th, 2010, 05:50 AM
#2
Re: unresolved external symbol "int __cdecl _.." between C and Cpp file
Remove the extern keyword from your function.h header file so that it becomes:
Code:
#ifndef FNC_H
#define FNC_H
void function(int a, int b);
#endif
-
April 20th, 2010, 06:29 AM
#3
Re: unresolved external symbol "int __cdecl _.." between C and Cpp file
That does not solve my problem and I still get the same error.
If I rename the file from .c to .cpp, I obtain something like 400 errors (obviously I made simple here the code for readability purpose) for syntax overloading stupid things..
I don't know how to solve really
-
April 20th, 2010, 07:03 AM
#4
Re: unresolved external symbol "int __cdecl _.." between C and Cpp file
Sorry, I didn't notice that it was a main.cpp and not a main.c. The problem is that you basically need to put the function(a,b) declaration in your function.h file within an extern "C" statement, with the caveate that you will only want that extern "C" statement to be seen in the compilation with the main.cpp file, but not with the compilation of the function.c file.
Thus the solution is to rewrite your function.h file as follows:
Code:
#ifndef FNC_H
#define FNC_H
#ifdef __cplusplus
extern "C"
{
#endif
void function(int a, int b);
#ifdef __cplusplus
}
#endif
#endif
Also, in the example you supplied you have a spurious ; at the end of your function signature in function.c.
-
April 20th, 2010, 02:19 PM
#5
Re: unresolved external symbol "int __cdecl _.." between C and Cpp file
You was right, thank you!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|