How would a loaded library function call a symbol in the main application?のコードを貼り付けて、ロードされたライブラリの仕組みを理解してください。そのようなファイル:共有オブジェクトファイルを開くことができません:私はそれを実行しようとしたとき、私はlibdlo.so LSロードされたライブラリは共有オブジェクトファイルを開くことができません:そのようなファイルまたはディレクトリはありません
@APG9591:/mnt/c/Users/fried/Desktop/KI3/Game$ gcc -shared -olibdlo.so dlo.c
/usr/bin/ld: /tmp/ccpGxAlo.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/tmp/ccpGxAlo.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
@APG9591:/mnt/c/Users/fried/Desktop/KI3/Game$ gcc -shared -fPIC -olibdlo.so dlo.c
@APG9591:/mnt/c/Users/fried/Desktop/KI3/Game$ gcc -ldl -rdynamic main.c
/tmp/ccHtUgDf.o: In function `main':
main.c:(.text+0x2b): undefined reference to `dlopen'
main.c:(.text+0x3b): undefined reference to `dlerror'
main.c:(.text+0x66): undefined reference to `dlerror'
main.c:(.text+0x7b): undefined reference to `dlsym'
main.c:(.text+0x83): undefined reference to `dlerror'
main.c:(.text+0xc7): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
@APG9591:/mnt/c/Users/fried/Desktop/KI3/Game$ gcc -Wl,--no-as-needed -ldl -rdynamic main.c
@APG9591:/mnt/c/Users/fried/Desktop/KI3/Game$ ls
AI_A.c AI_B.c AI_C.c a.out dlo.c Game.c Game.h libdlo.so main.c runGame.c
@APG9591:/mnt/c/Users/fried/Desktop/KI3/Game$ ./a.out
libdlo.so: cannot open shared object file: No such file or directory
@APG9591:/mnt/c/Users/fried/Desktop/KI3/Game$
を行う際に、ファイルが現在のディレクトリに権利はあるがしかし、それは、それがファイルを見つけることができないと言いますまたはディレクトリ
なぜ、プログラムがlibdlo.soファイルを見つけることができませんでしたか?この問題を解決するにはどうすればよいですか?ありがとう!
ローカルディレクトリは、Linuxがライブラリを探すフォルダの1つではありません。 libを '/ usr/lib'に移動するか、[このSOの回答]を見てください(http://stackoverflow.com/questions/13428910/how-to-set-the-environmental-variable-ld-library -path-in-linux) – LPs
dlopen呼び出しで、現在のディレクトリからライブラリをロードする場合は、相対パスを指定する必要があります。 EX: '。/ libdlo.so' – Ankur
リンクコマンドを並べ替える:' gcc -rdynamic main.c -ldl' –