Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > undefined symbol error

Reply
Thread Tools

undefined symbol error

 
 
eugene
Guest
Posts: n/a
 
      09-15-2005
I'm trying to compile and run some c++ code to be called from Matlab
(mex file)
and I'm getting "Invalid MEX-file ... undefined symbol" error. Anybody
knows
where to look for solution?

>>mex -v abc.cpp //that's how you "make" in Matlab, and that's what was called:


-> g++ -c ... abc.cpp
-> gcc -c ... /usr/local/matlab701/extern/src/mexversion.c
-> g++ ... -o abc.mexglx abc.o mexversion.o ... -L/home/eugene/lib
.... -lxyz ...

No errors so far.

>> abc //try to run and got error:


??? Invalid MEX-file '/home/eugene/matlab/abc.mexglx':
/home/eugene/lib/libxyz.so: undefined symbol: xyz_debug.

Code for libxyz.so has:
extern int xyz_debug;

abc.cpp has:
int xyz_debug = 0;

 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      09-15-2005
eugene wrote:
> I'm trying to compile and run some c++ code to be called from Matlab
> (mex file)
> and I'm getting "Invalid MEX-file ... undefined symbol" error. Anybody
> knows
> where to look for solution?


A MATLAB newsgroup or on the MathWorks website would probably be better
places to start. This group is for discussing C++ language issues, not
third-party tools.

Cheers! --M

 
Reply With Quote
 
 
 
 
eugene
Guest
Posts: n/a
 
      09-15-2005
mlimber wrote:
> eugene wrote:
> > I'm trying to compile and run some c++ code to be called from Matlab
> > (mex file)
> > and I'm getting "Invalid MEX-file ... undefined symbol" error. Anybody
> > knows
> > where to look for solution?

>
> A MATLAB newsgroup or on the MathWorks website would probably be better
> places to start. This group is for discussing C++ language issues, not
> third-party tools.
>
> Cheers! --M


Been there, done that
MathWorks website: do c++ at your own risk
MATLAB newsgroup: this is c/c++ problem

- symbol xyz_debug is defined in abc.cpp as "int xyz_debug = 0;"
- symbol xyz_debug is referenced in libxyz.so as "extern int
xyz_debug;"
The question is why after
-> g++ -c ... abc.cpp
-> gcc -c ... /usr/local/matlab701/extern/src/mexversion.c
-> g++ ... -o abc.mexglx abc.o mexversion.o ... -L/home/eugene/lib
.... -lxyz ...
try to run and got "undefined symbol xyz_debug" error?

 
Reply With Quote
 
=?iso-8859-1?Q?Ali_=C7ehreli?=
Guest
Posts: n/a
 
      09-15-2005
"eugene" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> - symbol xyz_debug is defined in abc.cpp as "int xyz_debug = 0;"
> - symbol xyz_debug is referenced in libxyz.so as "extern int
> xyz_debug;"
> The question is why after
> -> g++ -c ... abc.cpp
> -> gcc -c ... /usr/local/matlab701/extern/src/mexversion.c
> -> g++ ... -o abc.mexglx abc.o mexversion.o ... -L/home/eugene/lib
> ... -lxyz ...
> try to run and got "undefined symbol xyz_debug" error?


Try putting abc.o after -lxyz. If I'm not mistaken, the linker looks for
symbols in the successive files.

Ali

 
Reply With Quote
 
eugene
Guest
Posts: n/a
 
      09-16-2005
Ali Çehreli wrote:
> "eugene" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> > - symbol xyz_debug is defined in abc.cpp as "int xyz_debug = 0;"
> > - symbol xyz_debug is referenced in libxyz.so as "extern int
> > xyz_debug;"
> > The question is why after
> > -> g++ -c ... abc.cpp
> > -> gcc -c ... /usr/local/matlab701/extern/src/mexversion.c
> > -> g++ ... -o abc.mexglx abc.o mexversion.o ... -L/home/eugene/lib
> > ... -lxyz ...
> > try to run and got "undefined symbol xyz_debug" error?

>
> Try putting abc.o after -lxyz. If I'm not mistaken, the linker looks for
> symbols in the successive files.
>
> Ali


Still no luck.

g++ ... -Wl,-y,xyz_debug ... -lxyz ... abc.o ...
/home/eugene/lib/libxyz.so: reference to xyz_debug
abc.o: definition of xyz_debug

with same runtime error "undefined symbol xyz_debug".

Any ideas?

 
Reply With Quote
 
=?iso-8859-1?Q?Ali_=C7ehreli?=
Guest
Posts: n/a
 
      09-16-2005

"eugene" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
Ali Çehreli wrote:
> "eugene" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> > - symbol xyz_debug is defined in abc.cpp as "int xyz_debug = 0;"
> > - symbol xyz_debug is referenced in libxyz.so as "extern int
> > xyz_debug;"
> > The question is why after
> > -> g++ -c ... abc.cpp
> > -> gcc -c ... /usr/local/matlab701/extern/src/mexversion.c
> > -> g++ ... -o abc.mexglx abc.o mexversion.o ... -L/home/eugene/lib
> > ... -lxyz ...
> > try to run and got "undefined symbol xyz_debug" error?

>
> Try putting abc.o after -lxyz. If I'm not mistaken, the linker looks for
> symbols in the successive files.
>
> Ali
>
> Still no luck.
>
> g++ ... -Wl,-y,xyz_debug ... -lxyz ... abc.o ...
> /home/eugene/lib/libxyz.so: reference to xyz_debug
> abc.o: definition of xyz_debug
>
> with same runtime error "undefined symbol xyz_debug".
>
> Any ideas?


I wonder whether you are running against C vs. C++ linkage issues. If
xyz_debug has C linkage in libxyz.so, like because of being declared in a C
file, you have to define it as

extern "C" int xyz_debug = 0;

in abc.cpp.

Ali

 
Reply With Quote
 
eugene
Guest
Posts: n/a
 
      09-16-2005

Ali Çehreli wrote:
> "eugene" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) ups.com...
> Ali Çehreli wrote:
> > "eugene" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) oups.com...
> > > - symbol xyz_debug is defined in abc.cpp as "int xyz_debug = 0;"
> > > - symbol xyz_debug is referenced in libxyz.so as "extern int
> > > xyz_debug;"
> > > The question is why after
> > > -> g++ -c ... abc.cpp
> > > -> gcc -c ... /usr/local/matlab701/extern/src/mexversion.c
> > > -> g++ ... -o abc.mexglx abc.o mexversion.o ... -L/home/eugene/lib
> > > ... -lxyz ...
> > > try to run and got "undefined symbol xyz_debug" error?

> >
> > Try putting abc.o after -lxyz. If I'm not mistaken, the linker looks for
> > symbols in the successive files.
> >
> > Ali
> >
> > Still no luck.
> >
> > g++ ... -Wl,-y,xyz_debug ... -lxyz ... abc.o ...
> > /home/eugene/lib/libxyz.so: reference to xyz_debug
> > abc.o: definition of xyz_debug
> >
> > with same runtime error "undefined symbol xyz_debug".
> >
> > Any ideas?

>
> I wonder whether you are running against C vs. C++ linkage issues. If
> xyz_debug has C linkage in libxyz.so, like because of being declared in a C
> file, you have to define it as
>
> extern "C" int xyz_debug = 0;
>
> in abc.cpp.
>
> Ali


I was trying this. Does not work
Because libxyz.so is based on c++
Thanks anyway

 
Reply With Quote
 
Jay Nabonne
Guest
Posts: n/a
 
      09-17-2005
On Thu, 15 Sep 2005 13:47:45 -0700, eugene wrote:

> mlimber wrote:
> - symbol xyz_debug is defined in abc.cpp as "int xyz_debug = 0;"
> - symbol xyz_debug is referenced in libxyz.so as "extern int
> xyz_debug;"
> The question is why after
> -> g++ -c ... abc.cpp
> -> gcc -c ... /usr/local/matlab701/extern/src/mexversion.c
> -> g++ ... -o abc.mexglx abc.o mexversion.o ... -L/home/eugene/lib
> ... -lxyz ...
> try to run and got "undefined symbol xyz_debug" error?


This seems like a gcc problem, not a MATLAB one. It's having problems
resolving a symbol in the .so file when the .so is being loaded at
runtime. You could probably reproduce this without MATLAB.

So, I would suggest running this by a gcc newgroup.

- Jay

 
Reply With Quote
 
Jay Nabonne
Guest
Posts: n/a
 
      09-17-2005
On Sat, 17 Sep 2005 00:42:28 +0000, Jay Nabonne wrote:

> On Thu, 15 Sep 2005 13:47:45 -0700, eugene wrote:
>
>> mlimber wrote:
>> - symbol xyz_debug is defined in abc.cpp as "int xyz_debug = 0;"
>> - symbol xyz_debug is referenced in libxyz.so as "extern int
>> xyz_debug;"


Another thought: what happens if you reverse where the int is defined
(i.e. define it in the .so and make it extern from abc.cpp)?

- Jay

 
Reply With Quote
 
eugene
Guest
Posts: n/a
 
      09-19-2005

Jay Nabonne wrote:
> On Thu, 15 Sep 2005 13:47:45 -0700, eugene wrote:
>
> > mlimber wrote:
> > - symbol xyz_debug is defined in abc.cpp as "int xyz_debug = 0;"
> > - symbol xyz_debug is referenced in libxyz.so as "extern int
> > xyz_debug;"
> > The question is why after
> > -> g++ -c ... abc.cpp
> > -> gcc -c ... /usr/local/matlab701/extern/src/mexversion.c
> > -> g++ ... -o abc.mexglx abc.o mexversion.o ... -L/home/eugene/lib
> > ... -lxyz ...
> > try to run and got "undefined symbol xyz_debug" error?

>
> This seems like a gcc problem, not a MATLAB one. It's having problems
> resolving a symbol in the .so file when the .so is being loaded at
> runtime. You could probably reproduce this without MATLAB.


Program like abc.cpp (same definition / reference for xyz_debug) was
successfully
compiled and ran outside Matlab.

It looks as the problem is due to the way Matlab loads external code.
My hope
was that c++ folks would point out how to link the code so that
definition and
reference for xyz_debug would be in order.

- Eugene

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(Encryption Package) error: cannot find symbol symbol: class BaseNCode clusardi2k@aol.com Java 6 08-29-2012 08:33 PM
ld: 0711-317 ERROR: Undefined symbol: .__vec__delete2 modemer C++ 0 03-04-2005 03:26 PM
Undefined symbol __rtaccess() error fredy C++ 2 07-15-2004 11:54 PM
SWIG related: Error after installing m2crypto undefined symbol: EVP_rc5_32_12_16_ofb Sean Python 8 02-05-2004 09:53 PM
Symbol undefined? Linker error! el prinCipante C Programming 2 01-27-2004 12:25 AM



Advertisments