Include a compiled object file in a Visual Studio .NET 2003 project?

wildwolf

Golden Member
Jan 9, 2000
1,690
0
76
Hi there.

I need to include an object file in a Visual Studio .NET 2003 project in order to use some functions within that compiled source file. This is a visual c++ console application, btw.

However, nothing I try within the VS environment allows me include the file so that the project can find the functions listed within the implementation file. To get some specific information, I have the uncompiled source file of the header file: sorts.h and I have the compiled object code, sorts.obj (compiled from sorts.cpp <-- which I do not have). How can I include this sorts.obj file in my project so that I can use the functions outlined in the header file and defined in the .cpp implementation file without actually having the .cpp file?

Thanks,

wild-
 

tkdkid

Senior member
Oct 13, 2000
956
0
0
Can you get a dll instead of the object file? Then you can just add a reference to it and it should work fine.
 

squirtle24

Senior member
Apr 17, 2001
253
0
0
You should be able to link to the object file. So include the header where you need it and set the project to link to the .obj file.
 

wildwolf

Golden Member
Jan 9, 2000
1,690
0
76
Not sure if we can get it as a dll file. Not even sure how it would be referenced as a dll file.

There's got to be a way to tell the visual studio environment to use an object file when compiling/linking the executable so that we can do it this method, but it's escaped me thus far.

Thanks for the suggestion, I have passed it on, but hopefully somebody else has a method where we can use it as an object file.

 

wildwolf

Golden Member
Jan 9, 2000
1,690
0
76
You should be able to link to the object file. So include the header where you need it and set the project to link to the .obj file
That's just the problem, I can't figure out how/where to change visual studio to link to the object file. Any directions on that would be MOST appreciative.

 

squirtle24

Senior member
Apr 17, 2001
253
0
0
I use Visual C++ 6, not .NET, so the layout may be different. There should be an area where you can specify obj and lib files that the linker will use in addition to default obj files. So in VC6, it's in Project->Settings under the Link tab(object/library modules textbox).
 

wildwolf

Golden Member
Jan 9, 2000
1,690
0
76
The layout is quite different, I'm afraid.

.NET 2003 has a "Linker" option under properties, with the following tabs: General, Input, Debugging, System, Optimization, Embedded IDL, Advanced, and Command Line. And, unfortunately, in neither can I find an "object/library modules textbox".

If anybody with experience on .NET can lend a hand, I'd appreciate it.
 

wildwolf

Golden Member
Jan 9, 2000
1,690
0
76
Then at this point, I'd have to say that's something that MS has removed or made so dog gone impossible to figure out that it's a useless feature.

I've tried adding my allsorts.obj file to just about every location I can think that would make since in the "Linker" section under many tabs, including "Input" and nothing has worked to fix the unresolved external symbol link error. :(

Thanks for trying...and if anybody else has some suggestions, I'd appreciate it.
 

tkdkid

Senior member
Oct 13, 2000
956
0
0
Try project->add reference. That works for dll files anyway. I don't have c#, I use vb.net, so this may not be the same in c#.
 

squirtle24

Senior member
Apr 17, 2001
253
0
0
If no one else can tell you for certain which box to use, post a screenshot of the Input tab page and I should be able point out the right box. Wish I could just tell you, but I can't find any relevant screenshots or documentation for VS 2003.
 

wildwolf

Golden Member
Jan 9, 2000
1,690
0
76
best I can do for screenshots:

link

That's the 8 different "tabs" under the "Properties-->Linker" tab of the project.
 

wildwolf

Golden Member
Jan 9, 2000
1,690
0
76
Ah, found a way to check. It's the "Additional Dependencies" box.

But how do I add the object file in there? Merely adding the filename, allsorts.obj, still leads to unresolved external link errors.

 

squirtle24

Senior member
Apr 17, 2001
253
0
0
Hmm. Okay, if you are still getting external link errors after adding the filename, then I'd check to see if the header file is included in all source files that use those functions. You should be getting a fatal error "cannot open file 'allsorts.obj'", too, unless you put the actual object file into the workspace directory, where the .vcproj file is.

Edit:
Actually, I think I'm wrong about that. It's just not finding the functions you expect to be there in the obj file. Are you absolutely sure your object file matches your header file?

You can do a simple test to see that the linker is working for you. I did one just now.

Make one console project "test1", write a function called "test1" and have it output some text like "test1". Delete the main() function and compile. It won't build an exe, but it will compile a test1.obj.

Make a second console project "test2", and in main(), output "test2" and then call test1().

In the Additional Dependencies, be sure to add in test2.obj, and move the actual test2.obj into the test1 workspace directory. If you do all this, the test2 project should build an exe that prints "test2" and then "test1".
 

wildwolf

Golden Member
Jan 9, 2000
1,690
0
76
squirtle24,

Thanks, that has it going enough to work on the code more. The problem, evidently, is that it is a templated class, and thus VS .NET 2003 requires both the header and implementation file to be included in the main.cpp file, and since I couldn't include the source code that gave me the object file, the templated class wouldn't work.

I got the templated class to be changed to a non-templated class...and the object file can be included in the linker tab's additional dependencies section and it compiles and runs just fine.

Thanks again for the help.

Roger