LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-16-2005, 05:15 AM   #1
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Rep: Reputation: 30
shared libraries, dlopen and static member variables? (C/C++)


hiho@ll

i use dlopen to load a shared library
everything works perfectly until i use static member variables in my classes which are getting loaded by dlopen

the problem:
this works:
Code:
class example{
 int variable;
 example();
};
this not:
Code:
class example{
 static int variable;
 example();
};
from dlopen i get:
./../lib/libmylibrary.so.0: undefined symbol: _ZN6example11variableE

i didn't really found a topic why there should be a problem with static variables and this says u could use dlsym to get a pointer to a static variable

is shared library and static member variables a contradiction in terms?
or why does this not work?

maybe i forgot some compiler flag:
i use this for the library
g++ ./../utils/module.cpp -I./../utils/ -Wl,-export-dynamic -shared -o ./../lib/libmylibrary.so.0 \
-lpthread -lmysqlclient -I/usr/include/mysql -L/usr/lib/mysql -I./../utils \
-I/usr/local/pgsql/include -L/usr/local/pgsql/lib -lpq example.cpp

and this for my main prog which loads the library:
g++ -I./../utils/ -ldl -rdynamic -Wall -lmysql -L/usr/lib/mysql -I./../utils \
-I/usr/local/pgsql/include -L/usr/local/pgsql/lib -lpq -o ./main main.cpp

gdb didn't give any hint on this
and i don't think it could

thx@ll
 
Old 12-16-2005, 10:35 PM   #2
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
Static member variables are only declared in the class { }.
You also have to define them after the class declaration.
Put this after your class.

int example::variable;
 
Old 12-19-2005, 12:55 AM   #3
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Original Poster
Rep: Reputation: 30
youre right randyding
now it works perfectly

THX!!!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking static and shared libraries in the KDevelop Environment tristanm Programming 15 11-27-2006 09:59 PM
problem with opening shared library using dlopen() in Red Hat Linux phani@tcs Linux - General 1 01-10-2006 03:49 PM
Making static symbols private/local in shared libraries skoona Programming 1 02-18-2005 03:14 PM
compiling with shared and static libraries jinksys Programming 1 11-22-2003 04:54 AM
gaim trying to link static and shared libraries rose_bud4201 Linux - Software 0 09-28-2003 12:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration