Sponsored Content
Full Discussion: dlopen failed!
Top Forums Programming dlopen failed! Post 87724 by virmin on Thursday 27th of October 2005 05:53:28 AM
Old 10-27-2005
dlopen failed!

I can open my so file successfully by calling dlopen directly in my main function. But if I fork a child process, and call dlopen in child process, it failed!
I don't know why. Following is my code:
#include <stdio.h>
#include <errno.h>
#include <dlfcn.h>
void childFunc(void)
{
void *handle;

handle = dlopen("mytrd.so", RTLD_LAZY);
if( handle == NULL )
{
printf("errno[%d], errmsg[%s]\n", errno, dlerror());
return;
}
dlclose(handle);
}

void main(void)
{
int ret;
/* childFunc(); call directly, dlopen will success.*/

ret = fork();
if( ret == 0 )
{
childFunc(); /* dlopen will fail */
return;
}
else if( ret == -1 )
{
perror("fork");
retrun;
}
else
{
waitpid(ret);
}
}

Can anyone tell me why this happened? Is that a bug of Aix5.2 or there is anything wrong with my so file??The errmsg is "Bad address", the errno is 14.
 

10 More Discussions You Might Find Interesting

1. Solaris

dlopen issue with a dll

HI All, I am trying to use a dll using dlopen but in vain. When I try to ldd that dll it returns no output. Can anybody please tell me how I can load this dll in my process space. PS: ldd -l returns a lot of unsatisfied dependent symbols. Thanks a lot in advance Codeman (0 Replies)
Discussion started by: codeman
0 Replies

2. Programming

default location of libs in dlopen

Hi Where is the default location of libs to search, when we specify any lib in dlopen function. And if we want to specify a custom location, how will we do it? thanks. (1 Reply)
Discussion started by: sumsin
1 Replies

3. Programming

compile error while using dlopen

Hi unix lovers, I am getting error while compile a function which uses dlopen. My code is I am getting error as follows Am I missing something? I think I am missing a lot :-) I am using solaris. Thanks in advance, -Ashish (5 Replies)
Discussion started by: shriashishpatil
5 Replies

4. Programming

resolve_symbols: loader error: dlopen:

when i try to run an executable i got the following error message: resolve_symbols: loader error: dlopen: what does this error mean and what should be done to avoid this? with regards (1 Reply)
Discussion started by: gfhgfnhhn
1 Replies

5. Programming

dlopen help

//foo.c #include<stdio.h> int pen(int a) { printf("%d",a); } $cc -c foo.c $ls -shared -o libfoo.so foo.o ///////////now libfoo.so formed //i have already designed libfoo.so //main.c #include<stdio.h> #include <dlfcn.h> int main() { (2 Replies)
Discussion started by: lookforlohith
2 Replies

6. Solaris

dlopen() on dolaris

Dear experts, please help #include <stdio.h> #include <dlfcn.h> #include <link.h> #include <iostream.h> #include<stdlib.h> #include<errno.h> void main() { printf("\n in the main\n"); void *handle; handle = dlopen("my.so", RTLD_LAZY); if( handle ==... (2 Replies)
Discussion started by: vin_pll
2 Replies

7. Programming

Dynamic library load with dlopen

Hi, I created two library libsum.so and libproduct.so. In the libproduct.so is defined function "product" that use function "sum" defined in libsum.so. So libproduct depends on libsum. In main function I called product function by a dlopen request. Unfortunaly, when I execute program I have an... (5 Replies)
Discussion started by: shade82
5 Replies

8. Programming

Linux: dlopen fails to find symbols

I've attached a tar.gz containing three tests to demonstrate the problem I'm having. Within the tar are two shared libraries, two test applications, and a Makefile that builds the three tests. The shared libaries are libshlib1.so and libshlib2.so. Both export a function, libFunc, which takes... (5 Replies)
Discussion started by: DreamWarrior
5 Replies

9. AIX

Coredump in _Init when used dlopen() on AIX 6.1

Hello, One of our Customer is getting Coredump when our application is trying to load a library(one of our products library) using dlopen() on AIX 6.1. Our application and our shared library are built on AIX 5.3 machine using xlC compiler. we have tried executing the same application on... (2 Replies)
Discussion started by: erra_krishna
2 Replies

10. Programming

dlopen Linux vs. OSX

I've got a C++ program and some plugins ( shared objects ) that I have been developing for Linux. I was originally using and OSX machine to develop and test most of the code. I use dlopen to open the shared objects and then call methods from them. It behaves differently on Linux ( don't know the... (3 Replies)
Discussion started by: rfkrakora
3 Replies
DLOPEN(3)						   BSD Library Functions Manual 						 DLOPEN(3)

NAME
dlopen -- load and link a dynamic library or bundle SYNOPSIS
#include <dlfcn.h> void* dlopen(const char* path, int mode); DESCRIPTION
dlopen() examines the mach-o file specified by path. If the file is compatible with the current process and has not already been loaded into the current process, it is loaded and linked. After being linked, if it contains any initializer functions, they are called, before dlopen() returns. dlopen() can load dynamic libraries and bundles. It returns a handle that can be used with dlsym() and dlclose(). A second call to dlopen() with the same path will return the same handle, but the internal reference count for the handle will be incremented. Therefore all dlopen() calls should be balanced with a dlclose() call. If a null pointer is passed in path, dlopen() returns a handle equivalent to RTLD_DEFAULT. mode contains options to dlopen(). It must contain one or more of the following values, possibly ORed together: RTLD_LAZY Each external function reference is bound the first time the function is called. RTLD_NOW All external function references are bound immediately during the call to dlopen(). RTLD_LAZY is normally preferred, for reasons of efficiency. However, RTLD_NOW is useful to ensure that any undefined symbols are discovered during the call to dlopen(). If neither RTLD_LAZY nor RTLD_NOW is specified, the default is RTLD_LAZY. One of the following flags may be ORed into the mode argument: RTLD_GLOBAL Symbols exported from this image (dynamic library or bundle) will be available to any images build with -flat_namespace option to ld(1) or to calls to dlsym() when using a special handle. RTLD_LOCAL Symbols exported from this image (dynamic library or bundle) are generally hidden and only availble to dlsym() when directly using the handle returned by this call to dlopen(). If neither RTLD_GLOBAL nor RTLD_LOCAL is specified, the default is RTLD_GLOBAL. One of the following may be ORed into the mode argument: RTLD_NOLOAD The specified image is not loaded. However, a valid handle is returned if the image already exists in the process. This pro- vides a way to query if an image is already loaded. The handle returned is ref-counted, so you eventually need a correspond- ing call to dlclose() RTLD_NODELETE The specified image is tagged so that will never be removed from the address space, even after all clients have released it via dlclose() Additionally, the following may be ORed into the mode argument: RTLD_FIRST The retuned handle is tagged so that any dlsym() calls on the handle will only search the image specified, and not subsequent images. If path is NULL and the option RTLD_FIRST is used, the handle returned will only search the main executable. SEARCHING
dlopen() searches for a compatible Mach-O file in the directories specified by a set of environment variables and the process's current work- ing directory. When set, the environment variables contain a colon-separated list of directory paths, which can be absolute or relative to the current working directory. When path does not contain a slash character (i.e. it is just a leaf name), dlopen() searches the following until it finds a compatible Mach- O file: $LD_LIBRARY_PATH, $DYLD_LIBRARY_PATH, current working directory, $DYLD_FALLBACK_LIBRARY_PATH. When path looks like a framework path (e.g. /stuff/foo.framework/foo), dlopen() searches the following until it finds a compatible Mach-O file: $DYLD_FRAMEWORK_PATH (with framework partial path from path ), then the supplied path (using current working directory for relative paths), then $DYLD_FALLBACK_FRAMEWORK_PATH (with framework partial path from path ). When path contains a slash but is not a framework path (i.e. a full path or a partial path to a dylib), dlopen() searches the following until it finds a compatible Mach-O file: $DYLD_LIBRARY_PATH (with leaf name from path ), then the supplied path (using current working directory for relative paths), then $DYLD_FALLBACK_LIBRARY_PATH (with leaf name from path ). Note: If DYLD_FALLBACK_LIBRARY_PATH is not set, dlopen operates as if DYLD_FALLBACK_LIBRARY_PATH was set to $HOME/lib:/usr/local/lib:/usr/lib. Note: If DYLD_FALLBACK_FRAMEWORK_PATH is not set, dlopen operates as if DYLD_FALLBACK_FRAMEWORK_PATH was set to $HOME/Library/Frame- works:/Library/Frameworks:/Network/Library/Frameworks:/System/Library/Frameworks. Note: There are no configuration files to control dlopen searching. Note: If the main executable is a set[ug]id binary or codesigned with entitlements, then all environment variables are ignored, and only a full path can be used. Note: Mac OS X uses "universal" files to combine 32-bit and 64-bit libraries. This means there are no separate 32-bit and 64-bit search paths. RETURN VALUES
If dlopen() fails, it returns a null pointer, and sets an error condition which may be interrogated with dlerror(). SEE ALSO
dlopen_preflight(3) dlclose(3) dlsym(3) dlerror(3) dyld(1) ld(1) BSD
Aug 7, 2012 BSD
All times are GMT -4. The time now is 03:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy