473,396 Members | 1,871 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.

Linking Between Two Projects in a Solution

I have a solution with a two projects. The first project contains my classes
and an executable using those classes. The second project contains unit
tests for the classes. Because the unit test framework that I use requires a
main function I have to keep the tests in a separate project. Now when I try
to link the unit test project I get a lot of "Error LNK2019: unresolved
external symbol" errors. Both projects compile just fine and and the first
project creates OBJ files in the output directory. What should I do so that
the linker in the unit test project correctly links with the OBJ files of
the first project? Both of these projects should create executables.


Mar 21 '07 #1
3 2280
On 21 mar, 08:34, "Sami Lakka" <sami.la...@watechnologies.no_spam.com>
wrote:
I have a solution with a two projects. The first project contains my classes
and an executable using those classes. The second project contains unit
tests for the classes. Because the unit test framework that I use requires a
main function I have to keep the tests in a separate project. Now when I try
to link the unit test project I get a lot of "Error LNK2019: unresolved
external symbol" errors. Both projects compile just fine and and the first
project creates OBJ files in the output directory. What should I do so that
the linker in the unit test project correctly links with the OBJ files of
the first project? Both of these projects should create executables.
You need to add a reference to the 1st project in the 2nd project.

In Visual Studio 2005, right-click on the 2nd project in Solution
Explorer -"References..." -"Add New Reference" -"Projects" Tab -
choose your 1st project.
Arnaud
MVP - VC

Mar 21 '07 #2

<ad******@club-internet.frwrote in message
news:11*********************@y66g2000hsf.googlegro ups.com...
On 21 mar, 08:34, "Sami Lakka" <sami.la...@watechnologies.no_spam.com>
wrote:
>I have a solution with a two projects. The first project contains my
classes
and an executable using those classes. The second project contains unit
tests for the classes. Because the unit test framework that I use
requires a
main function I have to keep the tests in a separate project. Now when I
try
to link the unit test project I get a lot of "Error LNK2019: unresolved
external symbol" errors. Both projects compile just fine and and the
first
project creates OBJ files in the output directory. What should I do so
that
the linker in the unit test project correctly links with the OBJ files of
the first project? Both of these projects should create executables.

You need to add a reference to the 1st project in the 2nd project.

In Visual Studio 2005, right-click on the 2nd project in Solution
Explorer -"References..." -"Add New Reference" -"Projects" Tab -
>choose your 1st project.
That will only work for pure managed exes, or dll assemblies, because native
mixed exe assemblies aren't relocatable.

You probably will end up moving your common testable code into a dll.
That's needed for reusability in .NET anyway. In native C++, source code
reuse is a viable option as well, but that's what you're up against right
now.

If you want the same compiler options, package those .obj files into a
library (dll or static .lib). If you need different compiler settings,
include the source files in both projects.
Mar 21 '07 #3

"Ben Voigt" <rb*@nospam.nospama écrit dans le message de news:
u0**************@TK2MSFTNGP03.phx.gbl...
>
<ad******@club-internet.frwrote in message
news:11*********************@y66g2000hsf.googlegro ups.com...
>On 21 mar, 08:34, "Sami Lakka" <sami.la...@watechnologies.no_spam.com>
wrote:
>>I have a solution with a two projects. The first project contains my
classes
and an executable using those classes. The second project contains unit
tests for the classes. Because the unit test framework that I use
requires a
main function I have to keep the tests in a separate project. Now when I
try
to link the unit test project I get a lot of "Error LNK2019: unresolved
external symbol" errors. Both projects compile just fine and and the
first
project creates OBJ files in the output directory. What should I do so
that
the linker in the unit test project correctly links with the OBJ files
of
the first project? Both of these projects should create executables.

You need to add a reference to the 1st project in the 2nd project.

In Visual Studio 2005, right-click on the 2nd project in Solution
Explorer -"References..." -"Add New Reference" -"Projects" Tab -
>>choose your 1st project.

That will only work for pure managed exes, or dll assemblies, because
native mixed exe assemblies aren't relocatable.
Dooh! I missed the fact that the 1st project was an exe, sorry about that
:-(
If you want the same compiler options, package those .obj files into a
library (dll or static .lib).
Indeed. This is of course the solution....

Arnaud
MVP - VC
Mar 21 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: LY | last post by:
Hi I'm in the process of upgrading all our solutions and projects from ..NET 2002 to .NET 2003. Well, of course it did not go smoothly. I am running into a problem that I can't figure out. ...
0
by: Mythran | last post by:
Just wanted to let y'all know something that I dug up...maybe ya already knew. You know you can link files in .Net so you can work on 1 single file and have it compile for each project or...
3
by: Kevin Burton | last post by:
I am trying to use managed C++ but I am getting the following link errors: Metadata file 'D:\Projects\Visa\AddressVerification\AddressVerificat...
6
by: Rudy Ray Moore | last post by:
I work with a multi-project workspace. One project (the "startup" project) has a "Configuration Type" of "Application (.exe)". The other 40 projects have a "Configuration Type" of "Static Library...
0
by: Rudy Ray Moore | last post by:
I've been having trouble getting incremental linking to work under Visual C++ .net 2003 7.1 for my multi-project workspace. Ronald Laeremans and Carl Daniel (and a few others) helped me figure it...
0
by: Adam Clauss | last post by:
nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *,int,char const *,int)" (??3@YAXPAXHPBDH@Z) already defined in KomodiaInfraLib.lib(OSManager.obj)...
2
by: Joerg M. Colberg | last post by:
I have a VS.Net solution that contains various projects. Some of the projects contain programme blocks (legacy code) that are used by some of the other projects. One project contains some C code...
2
by: jkodroff | last post by:
Hi all, I am getting a bc30311 error (Value of type 'x' cannot be converted to 'x'). Note that the source and destination types are the same. I have run into this issue on 2 separate...
0
by: Philip Lowman | last post by:
I am in the process of trying to migrate a couple of build solutions to Visual Studio Express 2005 from VS 2003 Professional and I am running into a weird C/C++ runtime library linking issue when...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.