Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error LNK2019: unresolved external symbol. c file to cpp

There is a project made in C, its file is RawInput.c from http://www.codeproject.com/Articles/185522/Using-the-Raw-Input-API-to-Process-Joystick-Input. I have compiled it and it works perfect in vs2012. But when i pasted the same code within a cpp of a a new project i get 4 of these errors, just different decleration names. error LNK2019: unresolved external symbol "long __stdcall HidP_GetCaps(struct _HIDP_PREPARSED_DATA .... fatal error LNK1120: 4 unresolved externals i guess it has something todo with me trying to run c code within a c++ compiler without telling it the right way. Perhaps there must be extern "C" somewhere? I wouldnt know even tho i tryed my best to search the webb for solutions. Help would be appreciated. Thank you.

like image 332
user3033627 Avatar asked Nov 25 '13 19:11

user3033627


People also ask

How do I fix unresolved external symbol in C ++?

So when we try to assign it a value in the main function, the linker doesn't find the symbol and may result in an “unresolved external symbol” or “undefined reference”. The way to fix this error is to explicitly scope the variable using '::' outside the main before using it.

How do I fix LNK2019 error?

A symbol is declared but not defined Unless i and g are defined in one of the files included in the build, the linker generates LNK2019. You can fix the errors by including the source code file that contains the definitions as part of the compilation. Alternatively, you can pass .

What is an unresolved external in C++?

It means you have a linker problem. (The linker can't find a library with those symbols) You need to include the required library in your library path.

Why am I getting external symbol errors in lnk2019?

That's because the definition may be in a different source file or library. If a symbol is referred to but never defined, the linker generates an unresolved external symbol error. Here are some common problems that cause LNK2019:

What is an unresolved external symbol error?

The compiler can identify when a symbol isn't declared, but it can't tell when the symbol isn't defined. That's because the definition may be in a different source file or library. If a symbol is referred to but never defined, the linker generates an unresolved external symbol error. Here are some common problems that cause LNK2019:

Why is lnk2019 not working in Visual Studio?

Here are some common problems that cause LNK2019: The source file that contains the definition of the symbol isn't compiled In Visual Studio, make sure the source file that defines the symbol gets compiled as part of your project. Check the intermediate build output directory for a matching.obj file.

How do I fix lnk2019 errors in my build?

Unless i and g are defined in one of the files included in the build, the linker generates LNK2019. You can fix the errors by including the source code file that contains the definitions as part of the compilation. Alternatively, you can pass .obj files or .lib files that contain the definitions to the linker.


1 Answers

It seems that Hidsdh.h is not a C++ compatible header. Include it like this:

//This is not a C++ header
extern "C"
{
#include <Hidsdi.h>
}
like image 170
Andy Yelland Avatar answered Oct 06 '22 00:10

Andy Yelland