473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

error LNK2001: Linking error with VS C++ 6.0

When building my project, I'm getting following error:

Test1Dlg.obj : error LNK2001: unresolved external symbol "int __cdecl get_contact_state(enum CONTACT)" (?get_contact_state@@YAHW4CONTACT@@@Z)
Debug/Test1.exe : fatal error LNK1120: 1 unresolved externals

I have included the function by it's header in Test1Dlg.cpp so it should work. There is no error if I dont call the function.
The directory of the header file is known to the project, the other files would link without any problem.

Any idea what could be the problem would be helpful!
Aug 14 '07 #1
13 1956
JosAH
11,448 Expert 8TB
When building my project, I'm getting following error:

Test1Dlg.obj : error LNK2001: unresolved external symbol "int __cdecl get_contact_state(enum CONTACT)" (?get_contact_state@@YAHW4CONTACT@@@Z)
Debug/Test1.exe : fatal error LNK1120: 1 unresolved externals

I have included the function by it's header in Test1Dlg.cpp so it should work. There is no error if I dont call the function.
The directory of the header file is known to the project, the other files would link without any problem.

Any idea what could be the problem would be helpful!
Mentioning that function's prototype available just keeps the compiler's mouth shut.
There's still no guarantee though whether or not a compiled version of that function
exists and you have to make that compiled version available to the linker.

You didn't do that so the linker opened its mouth. If that function is stored in a
library you have to feed that library to the linker, otherwise if the compiled function
is just available in its own .o or .obj file you should feed that to the linker.

kind regards,

Jos
Aug 14 '07 #2
oler1s
671 Expert 512MB
The header allows the program to compile. You are getting a linker error, which means you forgot to link the library in. You need to specify the library directory and the actual library that gets linked in.
Aug 14 '07 #3
Thx for your help so far!
The function is NOT available via a library but as a obj-File located in the same dir than its header. Thats why Im expecting the linker to find it. Actually, all obj-Files are in the Debug-Folder where the compiler put them.
Aug 14 '07 #4
oler1s
671 Expert 512MB
The function is NOT available via a library but as a obj-File located in the same dir than its header. Thats why Im expecting the linker to find it.
Header files aren't compiled. Only source files are. Besides, the include directories and source file directories are not relevant to the linker. Only where the intermediate and linkage time files are. If it so happens that they are in the same folder as the header or source files, well, ok.

Actually, all obj-Files are in the Debug-Folder where the compiler put them.
Object files? As in get_contact_state is a function you wrote? Did you properly write up the code in a source file, as opposed to merely declaring the existence of such a function?
Aug 14 '07 #5
Did you properly write up the code in a source file, as opposed to merely declaring the existence of such a function?
Sure. I declared the function in a header, defined it in a source and included the header in the source-File using it (Test1Dlg). I compiled the source of the function independently with success so its obj-File is available in the Debug-Folder.
Aug 15 '07 #6
Banfa
9,065 Expert Mod 8TB
I compiled the source of the function independently with success so its obj-File is available in the Debug-Folder.
Independently? You mean outside of your normal project? If this is the case them the object will not be included on the link command which is why the symbol is unresolved, the linker can not find it in the objects and libraries it is linking.

You will have to either change the project linker settings to include the object as an input to the linker or add the C file to your project so that it just gets compiled and linked when you build the project normally.
Aug 15 '07 #7
JosAH
11,448 Expert 8TB
Thats why Im expecting the linker to find it.
A linker doesn't go hunting for the needed files. You have to explicitly supply it
with the files you want to have linked together. IDEs might hide this fact a bit
by doing it for you but linkers have other things to do; they don't hunt for, nor
find files for you.

kind regards,

Jos
Aug 15 '07 #8
Maybe I should have mentioned that I wanted to link obj-Files compiled from c-sources... Now that I renamed all c-Files to cpp everything workes fine :)
Thank you anyway!
Aug 15 '07 #9
JosAH
11,448 Expert 8TB
Maybe I should have mentioned that I wanted to link obj-Files compiled from c-sources... Now that I renamed all c-Files to cpp everything workes fine :)
Thank you anyway!
Oh great. Next time please supply correct and sufficient information along with
your question. This forum is not for guessing games.

kind regards,

Jos
Aug 15 '07 #10
Unfortunately, often it IS the problem to know which information is relevant and which not. If I guessed that the problem is with the c-Files, I propably had not posted this problem
Aug 15 '07 #11
weaknessforcats
9,208 Expert Mod 8TB
Maybe I should have mentioned that I wanted to link obj-Files compiled from c-sources... Now that I renamed all c-Files to cpp everything workes fine :)
Thank you anyway!
This is not what you do to get C object files in your executable.

If you have the source code, add the .c files to your project as .c files. Do not make a copy of the code. Add the files from the locations where they normally reside. .c files are compiled as C and .cpp files are compiled as C++.

C++ is not C. By renaming, something that compiled in C may no longer compile in C++ and if you fix it to compile in C++ it may no longer compile in C.
Aug 15 '07 #12
That is exactly what I wanted to do. But as I now know, obj-Files compiled from c are not compatible with cpp. You have to tell the compiler that you want to use a function defined in c explicitly.
Anyway, I'm just using quite basic c which should be compilable by an cpp compiler.
Aug 16 '07 #13
Banfa
9,065 Expert Mod 8TB
You have to tell the compiler that you want to use a function defined in c explicitly.
Yes but it isn't very hard to put

Expand|Select|Wrap|Line Numbers
  1. #ifdef __cplusplus
  2. extern "C" {              /* Declare declarations as C in a C++ file  */
  3. #endif  /* __cplusplus */
  4.  
  5. /* Function prototypes etc */
  6.  
  7. #ifdef __cplusplus
  8. }
  9. #endif  /* __cplusplus */
  10.  
  11.  
in your header file
Aug 16 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: We need more power captain | last post by:
Hi, I know less than a noob, I've been asked to do some compiles in VC++ 6 without knowing too much at all. (I'm a COBOL program normally so this is all too much for me) I open VC++6, open...
2
by: ozgan.net | last post by:
Hi everyone, I created my first COM object, but I took below errors. Why I didn't use socket functions. I defined *.def file __imp__WSAStartup@8 PRIVATE __imp__socket@12 PRIVATE...
1
by: yanwan | last post by:
Hello I met some problems in linking a project, and hope someone can give me some advice. -----------Configuration: lighting - Win32 Release-------------------- Linking... LINK : warning...
1
by: yanwan | last post by:
I met this problem in executing a c++ project in visual studio. Does anyone have suggestions to resolve "error lnk 2001"? --------------------Configuration: reconstruction - Win32...
3
by: Saurabh Aggrawal | last post by:
Hi, I am porting an application for 64-bit AMD processor and while linking the application i am getting the following errors: Processing directory uidll... Linking DLL...
2
by: Helen | last post by:
Hi I am trying to compile a package of avi to mpeg1 C source codes But I got the link error I searched actually my VFW.h and Vfw32.lib are all in the directory what should I do thanks a lot...
4
by: Sanjay Kumar | last post by:
Folks ! I am working with VC++ after a long time and having problem linking latest xerces 2.7 in VC++ 2005 Express Edition. I have done following: 1. downloaded and unpacked the the...
2
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
5
by: eberesche | last post by:
Hello, as a novice in ASN.1 I have me to a project in C ++ under use of ASN.1 - structures risquély. One of my colleagues means, this would deal something with masochism ;-). Result should be a DLL...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.