Linker error: undefined reference to `___builtin_vec_new'

E

Ed Dana

I'm trying to create a dynamic two dimensional array. My code looks like
this:
======================================================================
#define DEF_FrameBuffer_H

class FrameBuffer {
public:
FrameBuffer(int prmWidth, int prmHeight, unsigned long prmPen);
FrameBuffer(int prmWidth, int prmHeight);

private:
int clsHeight, clsWidth, clsCurrX, clsCurrY;
unsigned long **clsBuffer, clsPen;
};
======================================================================
#include <cstdlib>
#include <iostream>

#include <string>

// Declarations...
#ifndef DEF_FrameBuffer_H
#include "FrameBuffer.h"
#endif

// Constructors...
FrameBuffer::FrameBuffer( int prmWidth,
int prmHeight,
unsigned long prmPen
) {
int x, y;

clsWidth = prmWidth;
clsHeight = prmHeight;

clsBuffer = new unsigned long *[prmWidth];
if (clsBuffer) {
for (x = 0; x < prmHeight; x++) {
clsBuffer[x] = new unsigned long [prmHeight];
clsBuffer[x][y] = prmPen;
}
}
}

FrameBuffer::FrameBuffer(int prmWidth, int prmHeight) {
FrameBuffer::FrameBuffer(prmWidth, prmHeight, 0);
}
======================================================================

The program compiles fine, but the linker gives me the error: [Linker
error] undefined reference to `___builtin_vec_new'

I have no clue what this means except I suspect it has something to do
with the "new" keyword. As far as I can tell, this should work. This is
being compiled using Bloodshed's Dev-C++.

Any and all clues greatly appreciated.

Ed.
 
E

Ed Dana

OK, I just compiled this in Visual C++ and it compiled fine. It must be
a compiler problem, so I'm taking it over to the Bloodshed C++ forum.
Still, any clues are still welcome for any who are willing to help. :)
 
L

Lars Uffmann

Ed said:
OK, I just compiled this in Visual C++ and it compiled fine. It must be
a compiler problem, so I'm taking it over to the Bloodshed C++ forum.
Still, any clues are still welcome for any who are willing to help. :)

Undefined references usually mean that you included a header file
correctly (thus the compiler doesn't complain) but have to supply the
according library for the linker, so the precompiled function code can
be linked into your final executable. It should be solvable with the
correct -lLIBRARY option and maybe -LPATHTOLIBRARY for the linker.

Best Regards,

Lars
 
J

James Kanze

OK, I just compiled this in Visual C++ and it compiled fine.
It must be a compiler problem, so I'm taking it over to the
Bloodshed C++ forum. Still, any clues are still welcome for
any who are willing to help. :)

It's probably one of two things: your compiler is not installed
correctly, or for some reason, it is trying to link the code as
if it were C and not C++ (and thus not picking up the run-time
support for C++). (G++ will do this if you compile and link
with the command gcc: gcc is the basic compiler driver, which
doesn't really know about C++ -- it will invoke the correct
compiler, according to the source file suffix, but it will only
append the minimum libraries for C, typically libc.a on a Unix
system when linking. Invoking g++ will ensure that the C++
runtime support is linked in as well.)
 
J

James Kanze

Undefined references usually mean that you included a header
file correctly (thus the compiler doesn't complain) but have
to supply the according library for the linker, so the
precompiled function code can be linked into your final
executable. It should be solvable with the correct -lLIBRARY
option and maybe -LPATHTOLIBRARY for the linker.

The symbol he was missing was __builtin_vec_new. A symbol
starting with two underscores does not come from a user defined
library (hopefully, at least), but from the runtime support of
C++. The library with the necessary runtime support should be
pulled in automatically, *if* he uses a compiler driver to
invoke the link, that compiler driver is C++ aware, and knows
(or supposes) that the code being linked is C++.

(Note that the command we usually use to invoke the
"compiler"---cl, CC or g++ on my systems---really invokes a
compiler driver---a small program which invokes the actual
compiler, but also the linker, and in some cases the library
manager. And that while cl seems to be the only compiler driver
for VC++, and always supposes C++, cc and gcc exist along side
of CC and g++, and will not link in the C++ runtime support when
they invoke the linker.)
 
L

Lars Uffmann

James said:
The symbol he was missing was __builtin_vec_new. A symbol
starting with two underscores does not come from a user defined
library (hopefully, at least), but from the runtime support of
C++. The library with the necessary runtime support should be
pulled in automatically, *if* he uses a compiler driver to
invoke the link, that compiler driver is C++ aware, and knows
(or supposes) that the code being linked is C++.

Hmm - I guess I should keep my mouth shut and focus on my real strengths
- developing solutions rather than spread my very limited knowledge
about compiler and linker issues *g*

Didn't know the underscore-convention. Thanks for clearing that up.
 
E

Ed Dana

Reinstalling didn't work. However, your info got me to thinking... my
little experiment started as a C program, and then I switched it over to
C++. DevC++ allows me to change individual files between C and C++ but I
didn't see where I could do that at the project level. Creating a new
project as C++ and adding the original files back in fixed the problem.

Thanks for the clues! I needed them. ;)

Ed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top