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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

linking to object file

Status
Not open for further replies.

fishysheep

Programmer
Oct 13, 2001
54
GB
Hello

CAn anyone please tell me how to solve the following problem. I want to link my main program (containing #include myclass.h) to an object file.

I have 3 files
myclass.h (class interface)
myclass.cpp (member functions for class and #include "myclass.h")
mainprog.cpp (containg main and #include "myclass.h")
myclass.o (object file)

QUESTION
I should now be able to compile mainprog (which contains #include "myclass.h") - but when I do this I get linker errors saying that it cant call constructor or any member functions.

What I want to do is that I give .h and .o file to persons, but keep myclass.cpp away from them becuase of code. Is this possible?

thanks you.

All code fine, compiles ok when in same file.

 
for the linker you will need the .lib file not the .o or .obj file. The lib file is unreadable for a third party. These is the usual way the components are traded.

To instruct the linker to add the reference to your .lib usually you put a line in stdafx.h like:

#pragma comment(lib, "Mylib");

take care not to put Mylib.lib, it does not need the extension.

HTH,
s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top