error LNK2019
-
I have an header file, where I have a function:
#ifdef __cplusplus
extern "C" {
#endif
....
struct_t* function_new(const struct_type_t* test);
...
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endiffor this function I get 2 links errors:
error LNK2019: unresolved external symbol _function_new referenced in function ....
now, in cpp file, of course that I have the body of this function, but is not recognized at all ... if this body function is written in cpp, or if I would delete the body of this function, the error is exactly the same ... strange, no ? What could be the problem here, I am struggle to solve this error for days ...
-
I have an header file, where I have a function:
#ifdef __cplusplus
extern "C" {
#endif
....
struct_t* function_new(const struct_type_t* test);
...
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endiffor this function I get 2 links errors:
error LNK2019: unresolved external symbol _function_new referenced in function ....
now, in cpp file, of course that I have the body of this function, but is not recognized at all ... if this body function is written in cpp, or if I would delete the body of this function, the error is exactly the same ... strange, no ? What could be the problem here, I am struggle to solve this error for days ...
For some reason the implementation file is not being built into your project. Once again we need more details in order to help you. I would suggest that you move to using the Visual Studio IDE to build your projects as it is easier to see why problems like this occur, and you also get a standard structure for your projects.
-
I have an header file, where I have a function:
#ifdef __cplusplus
extern "C" {
#endif
....
struct_t* function_new(const struct_type_t* test);
...
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endiffor this function I get 2 links errors:
error LNK2019: unresolved external symbol _function_new referenced in function ....
now, in cpp file, of course that I have the body of this function, but is not recognized at all ... if this body function is written in cpp, or if I would delete the body of this function, the error is exactly the same ... strange, no ? What could be the problem here, I am struggle to solve this error for days ...
-
The name
function_new
in your header file and the name**_**function_new
reported by the linker do not match. Maybe the start of a track to explore here?while (!(success = Try()));
-
I have an header file, where I have a function:
#ifdef __cplusplus
extern "C" {
#endif
....
struct_t* function_new(const struct_type_t* test);
...
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endiffor this function I get 2 links errors:
error LNK2019: unresolved external symbol _function_new referenced in function ....
now, in cpp file, of course that I have the body of this function, but is not recognized at all ... if this body function is written in cpp, or if I would delete the body of this function, the error is exactly the same ... strange, no ? What could be the problem here, I am struggle to solve this error for days ...
Some things that might have gone wrong: 1. You did not link the object file containing the implementation to your program. Check your build options to make sure it's there. 2. The declaration in your header does not match your implementation. Make sure there is no typo, the argument type and number matches, and ... 3. ... that it's compiled as C code. You mentioned a cpp file: if your compiler deducts how to compile a file by it's suffix, it may have compiled a C++ instead of a C function! In that case the linker won't find it. You could check your compiler's documentation for an option to force compilation as C. Alternately, just to find out you're on the right track, try removing 'extern "C"' in your header to find out whether that's actually the cause. P.S.: Here's a good site pointing out all the details you need to watch out for when mixing C++ and C: How to mix C and C++[^]
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
-
Some things that might have gone wrong: 1. You did not link the object file containing the implementation to your program. Check your build options to make sure it's there. 2. The declaration in your header does not match your implementation. Make sure there is no typo, the argument type and number matches, and ... 3. ... that it's compiled as C code. You mentioned a cpp file: if your compiler deducts how to compile a file by it's suffix, it may have compiled a C++ instead of a C function! In that case the linker won't find it. You could check your compiler's documentation for an option to force compilation as C. Alternately, just to find out you're on the right track, try removing 'extern "C"' in your header to find out whether that's actually the cause. P.S.: Here's a good site pointing out all the details you need to watch out for when mixing C++ and C: How to mix C and C++[^]
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)