Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9085819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:20:18+00:00 2026-06-16T21:20:18+00:00

I’m new to unity builds. I’ve been doing some research and I’ve gotten great

  • 0

I’m new to unity builds. I’ve been doing some research and I’ve gotten great info from:

  • http://buffered.io/posts/the-magic-of-unity-builds/
  • http://oj.blackapache.net.s3.amazonaws.com/UnityBuilds.html

However, now that I started making changes to some of my projects, I’m a little confused.

For simplicity’s sake, let’s say I have only 2 projects in my solution. A library project (it creates a .lib file) and an executable project. Let’s call them LibProj and ExecProj.

This is how each project looks like:

LibProj
>include
>>Client.hpp<br>
>>Driver.hpp<br>
>>Verbose.hpp

>source
>>Client.cpp<br>
>>Verbose.cpp

ExecProj
>source
>>MyMainFile.cpp<br>
  Verbose.cpp

Verbose.cpp is used for debugging purposes. It wraps the ostream, so instead of using cout <<, I use verbose <<. This is done to control when verbose output is displayed to the console. In my release variants, all verbose output is skipped.

The reason why I have a copy of Verbose.cpp in both projects is so that I can get verbose output in my ExecProj without having to build LibProj in debug.

Driver.hpp and Client.cpp use verbose <<. MyMainFile.cpp calls functions in both of them.

Needless to say, with the normal way of building everything works.

Now the problem…

I created Unity.cpp inside LibProj. Its contents are:

#include "Client.cpp"
#include "Verbose.cpp"

LibProj builds just fine. However, when I build ExecProj, it breaks during linking:

LibProj.lib(Unity.obj) : error LNK2005: "public: void __thiscall VerboseMonitor::print(char const *,int)"
(?print@VerboseMonitor@@QAEXPBDH@Z) already defined in Verbose.obj
LibProj.lib(Unity.obj) : error LNK2005: "public: __thiscall VerboseStream::VerboseStream(void)" 
(??0VerboseStream@@QAE@XZ) already defined in Verbose.obj
C:\Users\\...\ExecProj.exe : fatal error
LNK1169: one or more multiply defined symbols found

So basically, it complains because we are redefining the verbose functions that already exist in the lib file.

My question is, why does it work when the files are compiled separately, but it doesn’t work with the unity build?

What makes one .lib file different than the other? I mean, technically LibProj.lib has symbols for VerboseMonitor::print in both build cases, and those symbols are redefined by ExecProj. However, the unity build case fails.

One way to work around this issue is by creating another lib file that only contains Verbose.cpp and removing it from both projects. However, I would like to understand why this is happening first.

Also, can someone think of a better way to work around this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:20:20+00:00Added an answer on June 16, 2026 at 9:20 pm

    I think I know what’s going on.

    Unity.cpp contains Verbose.cpp and Client.cpp
    -Verbose.cpp has the implentation of print.
    -Client.cpp includes Verbose.hpp which brings in the implementation of print.
    So Unity.obj has 2 implementations of print.

    This means that the library (LibProj.lib) contains one .obj file with print duplicates. So when we try link to the library, the compiler doesn’t know which print to use.

    The reason why this works on regular builds is that normally, Verbose.cpp creates Verbose.obj which contains an implementation of print in it, and Client.cpp creates Client.obj which contains an implementation of print in it as well. This means that the library (LibProj.lib) contains two .obj files with print defined in each, so the compiler picks one (I don’t know how, though).

    To test this theory, I created 2 Unity files.
    Unity.cpp includes Verbose.cpp
    Unity2.cpp includes Client.cpp

    With this implementation, I’m able to build. That’s because LibProj.lib now has two .obj files (Unity.obj & Unity2.obj), each containing an implementation of print, so there’s no symbol clashing.

    This is just an educated guess and I reserve the right to be wrong :). However, if I’m wrong, please correct me.

    Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.