GMR
GMR

Reputation: 25

LNK2001 - should be simple to solve.. but I just can't see it! (VS2005)

I'm banging my head here.. trying to resolve these LNK2001 errors. The help pages give me lots of reasons why, but I can't see which one applies.

Please could a knowledgable VS 2005 C++ person assist with these? ask me questions.. that sometimes helps. If I wasn't scared of looking like a mentalist I'd get a rubber duck to explain this to :-) but I sit in an office.

error LNK2001: unresolved external symbol "struct ethernetParams_t * ethernetData_g" (?ethernetData_g@@3PAUethernetParams_t@@A) simple_Console.obj

My code simple_console.cpp is trying to use a structure defined in C in but the way that the #includes work and the #stdafx is beyond me. The header containing ethernetParams_t is included in stdafx.h

#include "CON_ethernet_defs.h"

Please ask away... is the clue in the bit after the @@?

Upvotes: 0

Views: 149

Answers (3)

MiMo
MiMo

Reputation: 11983

@Attila and @mox probably nailed it: you need to link with the obj or lib file containing the implementation of the function(s) you are using.

If you right-click on you project in the Solution Explorer, click on Properties and then select Linker|Input you can see and edit the list of libraries/object files your are linking to ('Additional Dependencies').

You say that the structure is defined in C and not C++, another possible problem then is a missing extern "C" in the include file, see explanation here.

Upvotes: 0

mox
mox

Reputation: 6324

In order to consume the code that someone else developed (e.g. by using a static library in your case), you need two things:

  1. provide the function(s) signatures into your project (the include file)
  2. provide the functions(s) implementation into your project (the library file)

It looks like you did the first but not the second thing. This is how to interpret the error the linker is giving in this very cryptic form...

Upvotes: 1

Attila
Attila

Reputation: 28782

The linker is telling you that there is an unknown external symbol ethernetData_g that has type struct ethernetParams_t *. The cause of this is that although ethernetData_g is declared in the header you include, its definition comes from another object file that you need to link against. Since you are not linking with the approriate object file, the linker cannot find the proper definition

The object file you are missing must come from the library you are attempting to use, so look in that folder for .obj files

Upvotes: 1

Related Questions