Maybe the name of the function in .c file is different.
Or, if you are trying to use the function in .cpp files, then try this form of #include (in .cpp files only):
extern "C"
{
#include "MyHeaderFile.h"
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
hi, I am trying to convert some code from c++ to pure c, or at least most of it
When I had things in c++ I could make a .h file, then a .cpp file and simply type the implementation of functions declared in the .h in the .cpp; I did not have to edit linker files or anything like that, and the ide would keep track of it all, and I had no linker problems even if a function was not a member of a class
Now I have a .h, but when I try to use a function defined in the .c, which is declared in the .h, I get a LNK2019 unresolved external symbol "void __cdecl LC_iniciar_trace(char const *)" (?LC_iniciar_trace@@YAXPBD@Z) referenced in function _wWinMain@16 LC 1 C:\Users\xxxxx\Documents\Proyectos\plataforma multimedia c puro v1\Visual Studio\LC 1\LC 1.obj
Why is in not able to see the function implemented in a .c file in the same project? If I make a syntax error in the function the compiler would give an error, so is not as if the compiler does not see the .c file or anything like that
tnx
Maybe the name of the function in .c file is different.
Or, if you are trying to use the function in .cpp files, then try this form of #include (in .cpp files only):
extern "C"
{
#include "MyHeaderFile.h"
}
Hi, thank you both. By just changing the extension from .c to .cpp the errors stopped, but I willl use the extern c suggestion, thanks
In case you haven't discovered why you needed the changes to eliminate the link error(s), the following references should help clarify the issue.
Name Decoration
https://learn.microsoft.com/en-us/cpp/error-messages/tool-errors/name-decoration?view=msvc-170
"Use extern "C" to call a C function from C++. extern "C" forces use
of the C naming convention for non-class C++ functions. Be aware of
compiler switches /Tc or /Tp, which tell the compiler to ignore the
filename extension and compile the file as C or C++, respectively.
These options may cause linker names you don't expect."
Decorated names
https://learn.microsoft.com/en-us/cpp/build/reference/decorated-names?view=msvc-170
"Functions, data, and objects in C and C++ programs are represented
internally by their decorated names. A decorated name is an encoded
string created by the compiler during compilation of an object, data,
or function definition. It records calling conventions, types, function
parameters and other information together with the name. This name
decoration, also known as name mangling, helps the linker find the
correct functions and objects when linking an executable."
extern (C++)
https://learn.microsoft.com/en-us/cpp/cpp/extern-cpp?view=msvc-170
"extern "C" specifies that the function is defined elsewhere and uses
the C-language calling convention. The extern "C" modifier may also
be applied to multiple function declarations in a block."
Advanced detailed explanation:
Visual C++ name mangling
https://en.wikiversity.org/wiki/Visual_C%2B%2B_name_mangling