473,395 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

undefined symbol error

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;

Sep 15 '05 #1
10 8028
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

Sep 15 '05 #2
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?

Sep 15 '05 #3
"eugene" <kr*****@netscape.net> wrote in message
news:11**********************@g44g2000cwa.googlegr 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

Sep 15 '05 #4
Ali Çehreli wrote:
"eugene" <kr*****@netscape.net> wrote in message
news:11**********************@g44g2000cwa.googlegr 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?

Sep 16 '05 #5

"eugene" <kr*****@netscape.net> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Ali Çehreli wrote:
"eugene" <kr*****@netscape.net> wrote in message
news:11**********************@g44g2000cwa.googlegr 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

Sep 16 '05 #6

Ali Çehreli wrote:
"eugene" <kr*****@netscape.net> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Ali Çehreli wrote:
"eugene" <kr*****@netscape.net> wrote in message
news:11**********************@g44g2000cwa.googlegr 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 aC
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

Sep 16 '05 #7
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

Sep 17 '05 #8
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

Sep 17 '05 #9

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

Sep 19 '05 #10

Jay Nabonne wrote:
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


Cannot do that, libxyz.so is not mine and it's not open source :(

- Eugene

Sep 19 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Manuel Maria Diaz Gomez | last post by:
Hi Everybody, maybe you can give me a hint about this. I implemented a simple singleton Factory that will (among other things) keep a registry of objects. Objects register themself in the...
3
by: ch424 | last post by:
Hi there, I'm using Python 2.4.1 on Ubuntu Linux, and I'm having problems extending python in C: The C code is below: #include <Python.h> #include "ni488.h"
0
by: pervinder | last post by:
Hi, I have a c++ application which depends on some other libs which uses stlport When i build the application, it works fine on sun/linux/hp platform. (provided the .a for the dependency libs) ...
4
by: r.nikhilk | last post by:
Hi, We are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by including the...
4
by: Mathias Waack | last post by:
Hi, I've embedded python into a legacy application. It works - most of the time. In some special situations the app crashes executing the "import random". There are two different situations: ...
8
by: pavan734 | last post by:
Hello, Please excuse me as Iam not posting this to correct group. I have a parser code obtained from flex command. I have many other files. When I compile them Iam getting a message like:...
1
by: yamitmehta | last post by:
When I compile to code using g++arm of VxWorks 5.5 and put it on my board i get the follwing undefined symbols:- Cpool and Csingleton are template classes. CPool has the static member...
1
by: Justin Johnson | last post by:
Hello, I'm trying to build Python 2.5.0 on AIX 5.3 using IBM's compiler (VisualAge C++ Professional / C for AIX Compiler, Version 6). I run configure and make, but makes fails with undefined...
1
by: Michel Esber | last post by:
People, Environment: Linux AS4 I have just installed db2 v9.5 + Fixpak 2 on a machine that has db2 v8 up and running, but I am unable to create and instance: # ./db2icrt -a SERVER -p...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.