1

I'm a real beginner and I'm programming in C++ using Visual Studio. I've a simple cpp code that recalls some functions written in a .c and .h file. I included that file by means of #include directive and the IDE "sees" the function. When I compile, I get this

Error 7 error LNK2019: unresolved external symbol _IMUsendAccelToFIFO referenced in function _main D:\Cprojects\Pencil\Pencil\Pencil.obj Pencil

What am I missing here?

Thank you all!

default
  • 11,485
  • 9
  • 66
  • 102
stef
  • 737
  • 4
  • 13
  • 31
  • Are you linking it correctly? It seems a linker error, is the .o file generated from the .c file passed to the linker? – Ass3mbler Nov 28 '10 at 10:27
  • @Ass3mbler: If he's using VS that should be handled for him if it's his own code. I think it's probably more a problem that he isn't linking a required library in with his project. – OJ. Nov 28 '10 at 10:30
  • 1
    In silico: It's C related (read his question). – OJ. Nov 28 '10 at 10:32

5 Answers5

3

It is a linker error, not a compiler error. The compiler is happy, it saw the declaration of function in the .h file. The linker isn't, it cannot find the definition of the function.

Add the .c file to your project.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • the .c files are alrady in the project as "external dependencies", when I try to add them as "source files" I get this: Error 1 error C1853: 'Debug\Pencil.pch' precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa) d:\cprojects\pencil\pencil\imufifo.c 1 1 Pencil – stef Nov 28 '10 at 11:23
  • @Stefano: Then simply delete that old `.pch` file (or disable precompiled headers entirely). – fredoverflow Nov 28 '10 at 11:52
  • Right-click the .c file in the Solution Explorer window. Properties, C/C++, Precompiled Headers, change "Create/Use" to Not Using. – Hans Passant Nov 28 '10 at 13:27
0

Are you using ghettopilot? that's the only reference I can find on the web to the function you're missing. If you are, then you need to include the .lib file for that library in your link options.

OJ.
  • 28,944
  • 5
  • 56
  • 71
  • No I'm just importing some libraries I got from the vendor af the system I'm using, so they just should work – stef Nov 28 '10 at 11:27
  • @Stefano: see if there are any tutorials on how to set it up from your vendor. – default Nov 28 '10 at 12:23
  • The function that you're missing is from your vendor, who by the looks of it are using the library I mentioned. Make sure that you are linking in all your vendor libraries. – OJ. Nov 28 '10 at 22:39
0

Visual Studio will compile .c files as C and .cpp files as C++ by default, and this can cause trouble because if you want to call functions defined in a .c file from a .cpp file, then you must wrap the header in extern "C" { }, as the compiler will expect all functions not declared extern "C" to be from C++. This is because of an implementation detail called name mangling. Alternatively, you could force all files to be compiled as C or as C++ in the project settings.

Puppy
  • 144,682
  • 38
  • 256
  • 465
0

If you get an error in Visual Studio you can actually google for the error code and you will get pretty extensive information for that. In this case, googling LNK2019 gives this MSDN page as first hit, which also provides some examples on how you get the error.
Your vendor should have provided some .lib files for you (usually found in a folder named lib?). Make sure that these are added in the project via:

  • Project > Properties > Configuration Properties > Linker > Input > Additional Dependencies

You could also see if there is any "get started" information for you from your vendor, which explains which dependencies you have to include in your project.
If you feel unsure of what a compiler and what a linker does, pick up a book that explains it, or browse some free alternatives.

Community
  • 1
  • 1
default
  • 11,485
  • 9
  • 66
  • 102
0

Solved! Thank you very much! The libraries I was using needed to be built. I tried but I couldn't build them as I used to get "heap space" error!

I installed Visual Studio 2005 (with which the code was produced by the vendor) and it worked at first attempt! There are probably some back-compatibility issues..

stef
  • 737
  • 4
  • 13
  • 31