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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:36:12+00:00 2026-05-26T11:36:12+00:00

This is a puzzle to me: c++ undefined reference to destructor That’s the issue,

  • 0

This is a puzzle to me:

c++ undefined reference to destructor

That’s the issue, the code is the same as the link, full makefile and errors here. The linked answers did help but only to highlight that I had some headers in a place I did not expect.

makefile

CXX = g++

BIN = .

LIBS = -L.

INCLUDE = -I . -I 

CXXFLAGS = -pipe # -O6

LFLAGS = -lm

GeomTest_OBJS   =   geomTest.o SASAGeometry.o

geomTest_source =   SASAGeometry.cpp SASAGeometry.h sasa_transformMatrix.cpp sasa_transformMatrix.h geomSetup.cpp

SASAGeometry.o  :   SASAGeometry.cpp SASAGeometry.h sasa_transformMatrix.cpp sasa_transformMatrix.h

geomTest.o  :   geomSetup.cpp

geomTest    : $(GeomTest_OBJS) makefile
            $(CXX) -o geomTest.o -o SASAGeometry.o $(LIBS) $(INCLUDE) $(CXXFLAGS) $(geomTest_source) $(LFLAGS)
            $(CXX) $(LIBS) $(INCLUDE) $(CXXFLAGS) -o $(BIN)/geomTest geomTest.o SASAGeometry.o $(LFLAGS) 

clean       : \rm *.o *~ p1

I have both declared and instantiated the destructor AND not (allowing the compiler to do its thing)

error

geomSetup.cpp:(.text+0x5ab): undefined reference to `SASAGeometry::~SASAGeometry()'
geomSetup.cpp:(.text+0x5cd): undefined reference to `SASAGeometry::~SASAGeometry()'

no other errors. (sorry if its preferable to bump seemingly sorted issues rather than link to them, but my effort at that didn’t work)

Thanks in advance!

EDIT:

MAKE SURE TO COMPILE THE CORRECT SOURCE FILES, NOT THE OLD ONES YOU FORGOT TO COPY.

Hi @trojanfoe and @Kerrick SB, both answers made me look at my makefile and realise it was ugly. Here is the revised version. I am still getting the same ‘undefined reference to destructor’ error though:

makefile:

CXX = g++

BIN = .

LIBS = -L.

INCLUDE = -I. 

CXXFLAGS = -pipe # -O6

LDFLAGS = -lm

GeomTest_OBJS       =   sasa_transformMatrix.o SASAGeometry.o geomSetup.o

SASAGeometry.o      :   SASAGeometry.cpp SASAGeometry.h 

sasa_transformMatrix.o  :   sasa_transformMatrix.cpp sasa_transformMatrix.h 

geomSetup.o         :   geomSetup.cpp

geomTest                : $(GeomTest_OBJS)
                    $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+

clean           : \rm *.o *~ p1

error:

geomSetup.o: In function `main':
geomSetup.cpp:(.text+0x5ab): undefined reference to `SASAGeometry::~SASAGeometry()'
geomSetup.cpp:(.text+0x5cd): undefined reference to `SASAGeometry::~SASAGeometry()'
collect2: ld returned 1 exit status
make: *** [geomTest] Error 1

Why would the linker complain about the destructor and not the constructor or any other methods/functions in the class?

Thanks again!

  • 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-26T11:36:13+00:00Added an answer on May 26, 2026 at 11:36 am

    Your executable output file and your object file geomTest.o have the same name! That’s bound to get you into trouble when the linker overwrites the object file.

    Change it to $(CXX) -o geomTest ..., or better even to $(CXX) $@ ... to avoid such problems in the future.

    In fact, you are misusing the linker command altogether: you just want to have one single -o option, and the objects are listed directly, without flags:

    g++ -o myprog main.o foo.o bar.o
    

    Within the Makefile, do yourself a favour and use magic macros:

    myprog: main.o foo.o bar.o
            $(CXX) $(LDFLAGS) -o $@ $+ $(LIBRARIES)
    

    Here -o $@ matches the target name, i.e. -o myprog, and $+ matches all the dependent names, i.e. main.o foo.o bar.o.

    The guiding idea behind using variables is that you should never say the same thing more than once if you can help it. So you can have myprog: $(MyObjects) as the rule, but then use $+ in the command line to avoid repetition of MyObjects. This improves locality and maintainability.

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

Sidebar

Related Questions

found this puzzle HERE ... I made a brute force solution and I would
I am beginner to java and was trying out this code puzzle from the
Here's Eric Lippert's comment from this post : Now that you know the answer,
I was microbenchmarking some code (please be nice) and came across this puzzle: when
This is a puzzle to me and I am really annoyed that I cannot
This is my Java code to solve this puzzle. I have a little experience
I have limited experience with joins, and this puzzle has me stumped. Here are
I came across this puzzle here . I can't figure out why NONE is
This is a puzzle for me, I am able to get three DropDownLists to
On this page http://equals.lsri.nottingham.ac.uk/puzzle/create , if you type something into an input and then

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.