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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:55:02+00:00 2026-05-30T01:55:02+00:00

I am attempting to compile a basic array wrapper template class into a .o

  • 0

I am attempting to compile a basic array wrapper template class into a .o file, to try and figure out how to make dynamic libraries. However, when compiling the source with

g++ -std=c++0x -c array.cpp

the resulting file is only ~650 bytes. I examined the file with nm, and found the only symbols it contained were

00000001 r _ZStL13allocator_arg
00000000 r _ZStL19piecewise_construct

which seem to be features of the C++11 compilation, as when compiled without the -std=c++0x flag they are gone.

Attempting to compile the program test code and all with the command

g++ -std=c++0x -o tester tester.cpp array.cpp

produces linker errors for everything in array.cpp but otherwise compiles cleanly.

I honestly have no idea what is going on with this. I can post the contents of array.cpp and array.hpp if you suspect this an issue with my code itself, rather than how I am compiling it.

  • 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-30T01:55:04+00:00Added an answer on May 30, 2026 at 1:55 am

    That’s normal. Templates only result in code when they’re instantiated, and you haven’t done that. You’ve only provided the template. While the compiler is compiling the template, it has no reason to generate any specific instances of the template with actual types filled in for the template arguments.

    Later, the compiler compiles the other source files, where you use the template type. That doesn’t cause instantiation, either. It merely tells the compiler that it should expect to find instances of the template elsewhere. The compiler notes that in the object files. The linker then looks for definitions that the compiler said it should find, but it fails.

    That’s why you’re always advised to provide definitions for your templates inline with the declaration, in the header. That way, when the compiler sees you use a template, it can instantiate the template right away, using the definition it saw in the header. If you use the template in multiple source files, you might end up with multiple definitions from instantiating the template multiple times, but that’s allowed, and the linker knows how to handle it.

    The alternative is to explicitly instantiate the templates in your array.cpp file, but it’s easier to just define the template members inline.

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

Sidebar

Related Questions

I'm attempting to compile a file that instantiates this class. GCC gives me cryptic
I am attempting to compile a new class template within the namespace cop4530. Do
I am attempting to compile a c++ class using gcc. Due to the nature
I'm attempting to compile code in a text file to change a value in
I am attempting to compile the following template based code in VC++ 2005. #include
I'm attempting to compile a working copy of the MagickNet class library (DLL) using
I'm attempting to compile the ZipStream library, it is effectivley a C++ wrapper for
As basic as this is, it took me a few minutes to figure out,
I'm attempting to use clojure.contrib.io's (1.2) append-spit to append to a file (go figure).
When attempting to compile my C# project, I get the following error: 'C:\Documents and

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.