Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overcome linker error

Status
Not open for further replies.

raydona

Programmer
May 12, 2005
27
GB
Hi,
Please bear with me, I am new to Visual C++.Net. I have included two projects to a blank solution, one a static class library (named Vending Machine Library), the other a Windows Forms Application (named Vending Machine Controls). In the property pages of the Forms Application, in General under C/C++ folder of Configuration Properties I have typed the relative path to the static library folder:
../ Vending Machine Library
Also under Configuration Properties, under Linker folder, under Input, for Additional Dependencies I have typed the relative path to the Debug build of the static library folder:
../ Vending Machine Library /Debug/ Vending Machine Library.lib
Despite all this I get the linker error: “fatal error LNK1104: cannot open file '../Vending.obj' Vending Machine Controls. I have no idea what the error means and how to rectify it. I wonder if anyone has any suggestions? I would be very grateful.
 
The problem is that the directory structure is 2 levels
Code:
vending library
+--Debug
   +--xxx.obj
   +--xxx.lib
+--Release
   +--xxx.obj
   +--xxx.lib
other program
+--Debug
   +--other.obj   
+--Release
   +--other.obj
You're one level out. The easy way is to remove your relative include and change the project dependencies. Say that other program depends on library. This will get Visual studio to put in the correct relative path.
 
Thank you for your help. I have done as you suggested. In the property pages of the Forms Application, in General under C/C++ folder of Configuration Properties I have removed the relative path to the static library folder:
../ Vending Machine Library
Also under Configuration Properties, under Linker folder, under Input, for Additional Dependencies I have removed the relative path to the Debug build of the static library folder:
../ Vending Machine Library /Debug/ Vending Machine Library.lib
Further, in Project Dependencies I have forced the project Vending Machine Controls to depend on Vending Machine Library. But now I get the error:
fatal error C1083: Cannot open include file: 'VENDING MACHINE
Controller.h': No such file or directory

VENDING MACHINE Controller.h is the header file in the library which contains the declaration of the class being referenced by Form1.h in project Vending Machine Controls. I wonder if you could tell me how I might resolve this?
 
You need the relative path to the static library folder in C/C++. You don't need it in Linker.
 
I am extremely grateful for all your help. I have followed your instructions and have overcome the previous errors. Can I trouble you just one more time.
The static library contains a singleton:
namespace Lorenzo
{ class VendingMachine
{ ...
After linking the C++ static library to the Windows Forms Application, I am trying to invoke a function in the singleton from inside a button’s click event with the following code:
VendingMachine::Instance()->function();
I get the following linker errors.
error LNK2028: unresolved token (0A00000D) "public: static class Lorenzo::VendingMachine * __clrcall Lorenzo::VendingMachine::Instance(void)" (?Instance@VendingMachine@ Lorenzo@@$$FSMPAV12@XZ) referenced in function "private: void __clrcall VendingMachineControls::Form1::chcolateSelectnButon_Click(class System::Object ^,class System::EventArgs ^)" (?chcolateSelectnButon_Click@Form1@VendingMachineControls@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) Vending Machine Controls.obj
error LNK2019: unresolved external symbol "public: int __clrcall Lorenzo::VendingMachine::makeSelection(int)const " (?makeSelection@VendingMachine@ Lorenzo@@$$FQBMHH@Z) referenced in function "private: void __clrcall VendingMachineControls::Form1::chcolateSelectnButon_Click(class System::Object ^,class System::EventArgs ^)" (?chcolateSelectnButon_Click@Form1@VendingMachineControls@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) Vending Machine Controls.obj
The library works fine with a console application, so there is no problem with the library. I wonder how I might overcome these errors? I would be very grateful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top