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

  • SEARCH
  • Home
  • 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 7168259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:44:40+00:00 2026-05-28T14:44:40+00:00

I have a strange problem. On Windows, with Visual Studio 2010 and also with

  • 0

I have a strange problem. On Windows, with Visual Studio 2010 and also with the Intel Compiler everything is linked as expected. But when I try to compile my code with CLang 3.0 on Linux, it does compile (and if I only use a single CPP file it does also link and run) but does not link.

The message is that there are multiple symbol definitions, referring to template instanciations. For example consider the following two lines in a header file shared across multiple compilation units:

 template<class T> void myFunc(T in) { }
 template<> void myFunc<int>(int in) { }

Now from the Linux linker I would get something along the lines of:

“file xyz”: Multiple definition of “myFunc(int in)”, first defined in “some file”.

But how would I prevent that? Since it works on Windows I suppose it should work on Linux too somehow?

The same goes for static template data members, which are more or less the same as above just that you declare a variable instead of a function. I would prefer if it worked for static template data members.

If everything else fails I suppose I could still create a “MakeAll.cpp” file which just includes all CPP there are, but that doesn’t sound like a desirable solution to me…

Thanks for your help!

  • 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-05-28T14:44:41+00:00Added an answer on May 28, 2026 at 2:44 pm

    In my understanding, you are in fact defining your template specializations multiple times, and this should also give you an error for Windows compilers.

    In your header file you are defining a function by providing a body:

    template<> void myFunc<int>(int in) { }
    

    This definition will exist in multiple compilation units and the linker should complain.

    The same rules apply for your template specialization as for ordinary non-template functions: Either use inline or use a separate declaration and definition, by putting

    template<> void myFunc<int>(int in);
    

    in a header and

    template<> void myFunc<int>(int in)
    {
        // ...
    }
    

    in a .cpp file.

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

Sidebar

Related Questions

I'm having a very strange problem. I'm using Visual Studio 2010 Ultimate on Windows
I have encountered a strange error. I use Windows 7 x64. Visual Studio 2010
Having a strange issue with Visual Studio 2010 Professional (running Windows Vista Home Premium
I have a strange problem that I could not solve. When I try to
I have a strange problem. I have designed a windows form application in c#
I have a problem with a c# assembly (.net 2.0 written using Visual studio
I'm facing a strange problem: I have a new installation of TFS 2010 on
I have a strange problem with a Windows Phone (7.1/Mango) app. My understanding is
I have experienced a strange problem in windows vista and above. When I use
I have strange problem with sharepoint and ajax functionality. We have an UpdatePanel placed

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.