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 8147619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:24:34+00:00 2026-06-06T14:24:34+00:00

I was starting to code a library, and decided to do a test, but

  • 0

I was starting to code a library, and decided to do a test, but I’m getting the error in the question title (Mac OSX, gcc-4.7.1):

tlib.cpp:

template <typename T>
T dobra(const T& valor){
  return valor*2;
}

tlib.h:

template <typename T>
T dobra(const T& valor);

test2.cpp:

#include "tlib.h"
#include <iostream>

using namespace std;

int main (int argc, char const *argv[])
{ 
  double b = dobra<double>(10);
  cout << b << endl;
  return 0;
}

Compiling:

no25-89:CPROP canesin$ g++ -dynamiclib -Wall -std=c++11 tlib.cpp -o libdobra.so
no25-89:CPROP canesin$ g++ test2.cpp -Wall -std=c++11 -o test2 -L. -ldobra
Undefined symbols for architecture x86_64:
  "double dobra<double>(double const&)", referenced from:
      _main in cctLJGqf.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
no25-89:CPROP canesin$ 
  • 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-06T14:24:35+00:00Added an answer on June 6, 2026 at 2:24 pm

    A fact of life in C++ is that you must include a complete implementation of a template in every compilation unit it’s used in, or restrict yourself to specific instantitions.

    In practice, this means that you either:

    1. Put what you’ve got in tlib.cpp into tlib.h. This is the most common solution.
    2. Restrict yourself to only ever using (say) dobra<double>, and put an explicit instantiation into tlib.cpp:

      template double dobra<double>(const double& valor);

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

Sidebar

Related Questions

I mainly code small programs for myself, but recently, I've been starting to code
I am just starting to learn about the code contracts library that comes standard
I am currently starting to use the boost library in qt creator(2.3.0), but the
What would be the advice on starting and organising a library of useful code
im starting the pseudo code of a new site, and want it to be
I have some code for starting a process (notepad), and dynamically makes a event
The code bellow is the small starting point for a new way ( for
I am starting to use some Java code which was written by someone else.
We are starting to write more and more code for an ASP.Net web application
I'm using this code as the starting point to an overhaul of our JavaScript

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.