C++ :: Shared Library Throws Exception But Not Caught
Jan 10, 2013
A test program of mine loads a shared library (.so file). A function call in the shared library throws an exception that I am trying to catch in the main function of my test program. (I know that exception is being thrown for sure, I wrote the library to do that.)
However in the main program, the exception is not being caught. The flow of program goes past the catch block like no error has occurred. I am using g++ and I load the shared file using -l option. Only trying to load the program statically I got the following error:
/usr/bin/ld: cannot find -lmy-shared-library
collect2: ld returned 1 exit status
Writing a smart array class for my C++ class. I'm running into a problem where the constructor apparently throws the wrong exception. Compiled on G++ with C++11 extensions enabled.
Code: // headers #include <iostream> #include <utility> #include <cctype> // stuff we need from namespace std using std::cout; using std::cin;
[Code] .....
When I try to check the error-handling code, when I enter a size less then two, Array's ctor throws InvalidSize, and gets caught, all good. But when I enter a letter, the ctor also seems to throw InvalidSize!
I've been reading about libraries; How to make them, how to use them, the different types of libraries, etc..
When using a shared library, does the program require that library to be installed on the computer after the program has been compiled into an .exe?
Ie.. if somebody downloaded a "Helloworld.exe" that I had compiled on my computer using a shared library (that wasn't part of a standard operating system), would they also need that shared library on their computer for the program to run without errors?
and for Static Libraries, when I compile a program using a static library, does it include in the final binary only the functions of the library that are actually used, or does the compiler add in the entire library?
I have created a shared object in Ubuntu (libMYLIB.so). I am now trying to compile a simple test program (testmylib.c) to see if the shared object is properly built. I am getting an error that the build cannot find the shared object. My build command is:
I have a class "Result" with a single template function Set(const std::string& arName, T& val) and a specialization of this function Set<Real>(const std::string& arName, Real& val) where Real is a typedef for double. The class is in a shared library and I use it in my main program. If I do result->Set<GLOBAL::Real>("U", 100.0); the wrong template function is called!
I check this by the output with std::cout.
Maybe it's a problem with the typedef.
If I link the object file of the Result class directly to my main program (no shared library), it works.
Say now I have a dll, loaded and run by a 32bit program. One of the things that I access from the program in the dll are several 1024x1024 int buffers. However I would like to put some data into those buffers from a external process. And I would like a separate thread in that external process for each buffer. Is there any way I can make that memory space accessible to the external process so I can use my own multi threaded memory transfers to pass that data over provided I ensure that the original process doesn't try to do anything with that data? And I would like to do this without resorting to the Read/WriteProcessMemory functions which are not threadsafe. In short, I want to set up direct memory access between the 2 programs without creating any intermediate shared memory buffers ie I want to set permissions for an existing memory space. Is this possible?
class MyOwner { ... int m_count; bool b_locked; };
[Code] ....
I am using an API where I create many MyObjects on the heap, and the API uses a separate thread to send messages to each object. Each MyObject contains a pointer to MyOwner.
Suppose I want to keep a count of all messages received in all MyObjects: How can I do this in a thread safe way?
I am assuming that the code I have written above will not be safe--at the very least it seems that it would potentially miss message counts when it was locked--not the worse case scenario for me. I am most concerned about not causing the application to crash.
I am not so experianced with c++ myself, but I need to evaluate if a certain idea might work.
I am working with a system for automation purposes that is running on a realtime OS in parallel to windows. Windows and the RTOS exchange data via shared memory. The application in the RTOS is compiled in C++. Now I would like to be able to influence the some data manipulation tasks in the RTOS application without changing the code of the RTOS application. So a concept like calling a dll.
My idea was to create a class with virtual methods in the RTOS application. The objects that are used should then be created on the Windows side with the same class prototype, but specific implementation of the virtual methods. The objects should then be moved to the shared memory, where they are used by the RTOS application.
Is something like this possible or am I completly on the wrong path?
someone told me to download the latest source and build that so i did, by unzipping it, cding to the source, running ./bootstrap.sh, ./b2, and finally ./b2 install. when i compile i get no errors but when i run it i get ./jade: error while loading shared libraries: libboost_regex.so.1.55.0: cannot open shared object file: No such file or directory
In interprocess communication(IPC) when processe have to share data among each other,why cant they all connect to one single file and share data with basic file handling functions such as read and write?
Why do we need
shared memory(shmget shmat(),shmdt()..etc) and mapped memory(mmap(),munmap()..etc)
I have one requirement to store an array of structure at shared memory. Also the shared memory should have one counter to store number of elements in the array.
I tried to look at some placed but didn't find anything relevant.
So my first question, is it possible that we can store two things on same shared memory. And second if not then how to achieve the same?
I am trying to initialize a 2D char array of strings into POSIX shared memory to be shared between 3 other processes. There are plenty of tutorials on how to use a pointer to share a single string or an integer between processes, but I could find no examples on how to initialize 1D or 2D arrays using mmap(). I have posted what I have so far below. It is the first program, which creates the shared memory object and initialize the array char files[20][2][100] with the value files[0][0][0] = '