Hi,
I'm trying to write an application which have a component that I like
to modify without restarting it.
Thus, I was thinking of using a shared object for that component.
However, in the example below, I haven't figured out a way to modify
commonClass.cpp (for example, the print() method) and be able to see
the changes without rerunning the application. I can see changes made
directly in sharedClass.cpp , though. Is there a way to see changes in
commonClass.cpp without restarting the application?
Thanks,
Izhar.
// main.cpp
#include <iostream>
#include <dlfcn.h>
#include <stdio.h>
#include <unistd.h>
#include "commonClas s.h"
#include "sharedClas s.h"
sharedClass* sharedClass_SO = NULL;
int main() {
while( true ) {
commonClass cc;
cc.print();
void *handle = dlopen ( "sharedClass.so ", RTLD_NOW );
if( handle == NULL ) {
std::cerr << dlerror() << std::endl;
exit( -1 );
}
sharedClass_SO->print();
delete sharedClass_SO;
dlclose( handle );
int x;
std::cin >> x;
}
return 0;
}
// commonClass.h
#ifndef _COMMON_CLASS_H _
#define _COMMON_CLASS_H _
class commonClass {
public:
commonClass(){} ;
void print();
};
#endif
//commonClass.cpp
#include <iostream>
#include "commonClas s.h"
void commonClass::pr int() {
// I CAN'T see changes here without re-running the application
std::cout << "commonClas s: XXXXXX" << std::endl;
}
// sharedClass.h
#ifndef _SHARED_CLASS_H _
#define _SHARED_CLASS_H _
class sharedClass {
public:
sharedClass(){} ;
virtual ~sharedClass() {};
virtual void print();
};
extern sharedClass* sharedClass_SO;
#endif
// sharedClass.cpp
#include <iostream>
#include "sharedClas s.h"
#include "commonClas s.h"
void sharedClass::pr int() {
commonClass cc;
// I CAN see changes here without re-running the application
std::cout << "sharedClas s: ";
cc.print();
}
extern "C" {
sharedClass* maker() {
return new sharedClass();
}
class proxy {
public:
proxy() {
sharedClass_SO = maker();
}
};
proxy p;
}
// Makefile
all: main sharedClass.so
commonClass.o: commonClass.cpp
g++ -Wall -c commonClass.cpp
sharedClass.o: sharedClass.cpp commonClass.o
g++ -Wall -c sharedClass.cpp
sharedClass.so: sharedClass.o
g++ sharedClass.o -shared -o sharedClass.so
main.o: main.cpp
g++ -rdynamic -Wall -c main.cpp
main: main.o commonClass.o
g++ -rdynamic main.o commonClass.o -ldl -o main
clean:
/bin/rm -f main *.o *.so 1 1869 iz***********@g mail.com wrote: [redacted]
You're OT here, I'm afraid.
You might try:
comp.unix.progr ammer
gnu.g++.help
Good luck. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Oliver |
last post by:
Hi,
I have a problem with a shared library of mine. I compile the *.o
files and then generate the .so lib with:
cc -shared libjava_vrpn.so *.o
When I then run my program I get an error for an unresolved symbol.
The symbols it's looking for are in another library called libvrpn.a,
but for some unknown reason the compiler does not uses this library
when I tell him to used.
|
by: Steve |
last post by:
Hi,
We have an application framework library that gets statically linked to any
applications we produce. (Windows apps, but I don't think that matters
here).
The framework is based heavily on the STL and the API uses many STL
constructs. Because of the static linking, and the fact that both app and
framework are built by the same compiler, we don't have any problems.
|
by: tropos |
last post by:
(Platform: Solaris with gmake and native Sun C++ compiler)
Problem: If I create a shared object (.so file) and load it into a
executable, the loader correctly runs constructors of static objects in
the .so file. But if I link the same code statically, with no shared
object, then the constructors don't run at all! Why??
Here's an example:
<file AnnounceConstruction.cpp>
|
by: Suneeel |
last post by:
Hi All,
I'm having a problem with STL on Red Hat Linux 9, gcc 4.1.0.
I have a Shared Object that is inserting an object into a MAP. When
this shared object is used, I get a runtime error saying
relocation error: /usr/lib/libMySharedObj.so: undefined symbol:
_ZSt29_Rb_tree_insert_and_rebalancebPSt18_Rb_tree_node_baseS0_RS_
|
by: Suresh369 |
last post by:
I have written a program which inherits a calss from a different shared object. I have linked that shared object when I compile my program using the -shared <path>/blah.so
My question is how exactly do I include the parent class in my program. When I tried to use
#include<parent.h>
class child : public parent {
}
| |
by: sirchia.r |
last post by:
Hi all,
I'm not very much of a C expert, so I hope one of you is willing to
help me out.
What I'm trying to do is create a shared object library SO1, to which
an executable E is already linked. The problem here is that SO1 itself
links to another shared object library SO2. Result is that E is not
linked to SO2 and I get the problem of undefined symbols at runtime...
|
by: David T. Ashley |
last post by:
I've occasionally had trouble compiling and linking programs that use shared
libraries. That never made a lot of sense to me, because I thought the
operating system went hunting for the symbols and libraries at runtime (and
not before).
Questions:
a)How do the development tools know that a given symbol (a function entry
point, for example) is located in a shared library and won't be linked in
statically?
|
by: Tim |
last post by:
Hello Everyone,
I am getting shared memory in python using the following.
szName = c_char_p(name)
hMapObject = windll.kernel32.CreateFileMappingA(INVALID_HANDLE_VALUE,
None, PAGE_READONLY, 0, TABLE_SHMEMSIZE, szName)
if (hMapObject == 0):
print "OpenKey: Could not open name file mapping object"
raise WinError()
|
by: abarun22 |
last post by:
HI
I am new to SWIG & Python and right now i am in the process of
wrapping some "C" functionalities present in a static library for
python. I do have my C file "name.c" which just contains some helper
functions.
I tried to link my object files (e.g name.o & name_wrap.o) with the
static libraries (whose functionalities need to be wrapped) to form a
shared library that can be imported from Python. While doing so i
cannot be able to access...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |