creating and using a dynamic shared library on solaris - c++

I am reading the procedure to create and use a dynamic shared library on solaris sparc server.
below are the file i have :
> ls -lrt
total 8
-rw-rw-r-- 1 nobody nobody 848 Nov 22 14:45 badmemlib.hh
-rw-rw-r-- 1 nobody nobody 1924 Nov 22 14:46 badmemlib.cc
-rw-rw-r-- 1 nobody nobody 330 Nov 22 14:49 my_prog.cc
>
in the above files badmemlib.hh is the header file using which i am creating a shared library with the below command following what is mentioned in this link.
> CC -G -o libbad.so -h libbad.so -Kpic badmemlib.cc
after i run the above command i have these below files:
> ls -lrt
total 26
-rw-rw-r-- 1 nobody nobody 848 Nov 22 14:45 badmemlib.hh
-rw-rw-r-- 1 nobody nobody 1924 Nov 22 14:46 badmemlib.cc
-rw-rw-r-- 1 nobody nobody 330 Nov 22 14:49 my_prog.cc
-rwxrwxr-x 1 nobody nobody 8284 Nov 22 15:11 libbad.so*
>
as you can see libbad.so is built without any errors.
Now my main is in the file my_prog.cc
i am compiling the file my_prog.cc as below which following this:
and there were no errors.the binary a.out is built.
> CC -L. -lbad my_prog.cc
> ls -lrt
total 184
-rw-rw-r-- 1 nobody nobody 848 Nov 22 14:45 badmemlib.hh
-rw-rw-r-- 1 nobody nobody 1924 Nov 22 14:46 badmemlib.cc
-rw-rw-r-- 1 nobody nobody 330 Nov 22 14:49 my_prog.cc
-rwxrwxr-x 1 nobody nobody 8284 Nov 22 15:11 libbad.so*
-rwxrwxr-x 1 nobody nobody 80224 Nov 22 15:14 a.out*
>
Now if i run a.out then the error i am facing is :
> ./a.out
ld.so.1: a.out: fatal: libbad.so: open failed: No such file or directory
Killed
It mentions that library is not found but as you can see above the library is in the same directory!
Could anybody pls help me!
content of my_prog.cc.it actually generates a sigsegv and and the badmemlib files has a signal handler.
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include "badmemlib.hh"
#ifdef SOLARIS /* needed with at least Solaris 8 */
#include <siginfo.h>
#endif
int main(){
char *where=(char *)0x123;
printf( "About to write to %p\n", where);
strcpy(where,"vijay");
return(0);
}

You need to tell your application to find .so file from your current directory:
CC -L. -lbad my_prog.cc -R <your current directory>
http://docs.oracle.com/cd/E18659_01/html/821-1383/bkana.html#bkawi

You can also try setting the LD_LIBRARY_PATH variable.
You should be doing:
export LD_LIBRARY_PATH = $LD_LIBRARY_PATH:<full path where library is present>

Related

"string.h" not found message in building qt app for iOS

I've recently updated Xcode to version 10.0 and after that when I try to build version for iOS I've the following problem.
1:04:17: Running steps for project Diasteca...
11:04:17: Starting: "/Users/belladellifabio/Qt/5.11.1/ios/bin/qmake" /Users/belladellifabio/Desktop/QtProjects/Diasteca/mqtt_test/mqtt_test.pro -spec macx-ios-clang CONFIG+=iphoneos CONFIG+=device CONFIG+=qml_debug
Project MESSAGE: This project is using private headers and will therefore be tied to this specific Qt module build version.
Project MESSAGE: Running this project against other versions of the Qt modules may crash at any arbitrary point.
Project MESSAGE: This is not a bug, but a result of using Qt internals. You have been warned!
11:04:18: The process "/Users/belladellifabio/Qt/5.11.1/ios/bin/qmake" exited normally.
11:04:18: Starting: "/usr/bin/make" qmake_all
make: Nothing to be done for `qmake_all'.
11:04:18: The process "/usr/bin/make" exited normally.
11:04:18: Starting: "/usr/bin/make"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -g -fPIC -std=gnu++11 -arch arm64 -arch x86_64 -Xarch_arm64 -miphoneos-version-min=12.0 -Xarch_arm64 -isysroot/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.3.sdk -Xarch_x86_64 -mios-simulator-version-min=12.0 -Xarch_x86_64 -isysroot/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.3.sdk -fobjc-nonfragile-abi -fobjc-legacy-dispatch -fembed-bitcode-marker -Wall -W -DQT_COMPILER_SUPPORTS_SSE2 -DMQTT_TEST_LIBRARY -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_NETWORK_LIB -DQT_CORE_LIB -I../../Diasteca/mqtt_test -I. -I../../../../Qt/5.11.1/ios/mkspecs/common/uikit -I../../../../Qt/5.11.1/ios/include -I../../../../Qt/5.11.1/ios/include/QtNetwork -I../../../../Qt/5.11.1/ios/include/QtCore/5.11.1 -I../../../../Qt/5.11.1/ios/include/QtCore/5.11.1/QtCore -I../../../../Qt/5.11.1/ios/include/QtCore -I. -I../../../../Qt/5.11.1/ios/mkspecs/macx-ios-clang -o qmqttclient.o ../../Diasteca/mqtt_test/qmqttclient.cpp
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.3.sdk' [-Wmissing-sysroot]
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.3.sdk' [-Wmissing-sysroot]
In file included from ../../Diasteca/mqtt_test/qmqttclient.cpp:30:
In file included from ../../Diasteca/mqtt_test/qmqttclient.h:33:
In file included from ../../Diasteca/mqtt_test/qmqttglobal.h:33:
In file included from ../../../../Qt/5.11.1/ios/include/QtCore/qglobal.h:47:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:202:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:61:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string.h:61:15: fatal error: 'string.h' file not found
Probably the real problem is not the file not found error, but is connected to the fact that qty tries to build the app using an SDK that is no more installed on the system. Is this a qt problem? How could I specify the version of iOS SDK to use to build the app? Is it possible?
Finally, I've found and delete .qmake.cache and .qmake.stash files. I've restart QtCreator and now it seems to work.
Qt stores SDK information somewhere deep in the build output and the .pro.user file.
Remove the user file (you might want to backup your user file in case you have custom build steps), the complete (shadow) build tree and modify your .pro file so that there is no such line as QMAKE_MAC_SDK = macosx10.13.
Then call qmake and build your project again, the inconsistency should be gone.
This occurs when the iOS SDK that Qt is expecting is different than the iOS SDK that you have installed. For instance Qt 5.13.1 expects iPhoneOS13.1.sdk but my Xcode currently has iPhoneOS13.2.sdk:
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs
$ ls -l
total 0
drwxrwxr-x 7 root wheel 224 Nov 5 2019 iPhoneOS.sdk
lrwxr-xr-x 1 root wheel 12 Jan 15 2020 iPhoneOS13.2.sdk -> iPhoneOS.sdk
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs
$ ls -l
total 0
drwxrwxr-x 8 root wheel 256 Jul 22 14:14 iPhoneSimulator.sdk
lrwxr-xr-x 1 root wheel 19 Jan 15 2020 iPhoneSimulator13.2.sdk -> iPhoneSimulator.sdk
To remedy this, we can get Qt to use the iPhoneOS13.2.sdk:
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs
$ ls -l
total 0
drwxrwxr-x 7 root wheel 224 Nov 5 2019 iPhoneOS.sdk
lrwxr-xr-x 1 root wheel 12 Jan 15 2020 iPhoneOS13.2.sdk -> iPhoneOS.sdk
$ sudo ln -s iPhoneOS.sdk iPhoneOS13.1.sdk
$ ls -l
total 0
drwxrwxr-x 8 root wheel 256 Jul 22 14:20 iPhoneOS.sdk
lrwxr-xr-x 1 root wheel 12 Jul 22 14:20 iPhoneOS13.1.sdk -> iPhoneOS.sdk
lrwxr-xr-x 1 root wheel 12 Jan 15 2020 iPhoneOS13.2.sdk -> iPhoneOS.sdk
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs
$ ls -l
total 0
drwxrwxr-x 8 root wheel 256 Jul 22 14:14 iPhoneSimulator.sdk
lrwxr-xr-x 1 root wheel 19 Jan 15 2020 iPhoneSimulator13.2.sdk -> iPhoneSimulator.sdk
$ sudo ln -s iPhoneSimulator.sdk iPhoneSimulator13.1.sdk
$ ls -l
total 0
drwxrwxr-x 8 root wheel 256 Jul 22 14:14 iPhoneSimulator.sdk
lrwxr-xr-x 1 root wheel 19 Jul 22 14:39 iPhoneSimulator13.1.sdk -> iPhoneSimulator.sdk
lrwxr-xr-x 1 root wheel 19 Jan 15 2020 iPhoneSimulator13.2.sdk -> iPhoneSimulator.sdk
I met a similar problem, because my xcode project was created by different XCode SDK, and it's generated by CMake, so I deleted the cache and solved the problem.

OCCI linkage: Undefined symbols

I have been working in a solution with Oracle database access and C/C++.
I'm using OCCI but we are in trouble to link in Solaris 11.
Solution works "like a charm" in Linux (OpenSUSE and Mint), but doesn't in Solaris 11.
Here environment informations:
I downloaded instantclient_11_2 (sun sparc version) and unpacked it in a Solaris folder
I created symbolic links to libclntsh.so.11.1 called libclntsh.so, and for libocci.so.11.1 called libocci.so. Bellow a "ls -l" showing files:
-rwxrwxr-x 1 f780333 desenv 23792 Aug 22 2013 adrci
-rw-rw-r-- 1 f780333 desenv 414 Aug 22 2013 BASIC_README
-rwxrwxr-x 1 f780333 desenv 41464 Aug 22 2013 genezi
lrwxrwxrwx 1 f780333 desenv 17 Apr 5 14:21 libclntsh.so -> libclntsh.so.11.1
-rwxrwxr-x 1 f780333 desenv 50268448 Aug 22 2013 libclntsh.so.11.1
-r-xr-xr-x 1 f780333 desenv 8653320 Aug 22 2013 libnnz11.so
lrwxrwxrwx 1 f780333 desenv 15 Apr 5 14:22 libocci.so -> libocci.so.11.1
-rwxrwxr-x 1 f780333 desenv 1545008 Aug 22 2013 libocci.so.11.1
-rwxrwxr-x 1 f780333 desenv 118735824 Aug 22 2013 libociei.so
-r-xr-xr-x 1 f780333 desenv 121800 Aug 22 2013 libocijdbc11.so
-r--r--r-- 1 f780333 desenv 2091135 Aug 22 2013 ojdbc5.jar
-r--r--r-- 1 f780333 desenv 2739616 Aug 22 2013 ojdbc6.jar
drwxrwxr-x 4 f780333 desenv 7 Aug 22 2013 sdk
-rwxrwxr-x 1 f780333 desenv 177680 Aug 22 2013 uidrvci
-rw-rw-r-- 1 f780333 desenv 66779 Aug 22 2013 xstreams.jar
I created another folder that contens symbolic links to important needs libraries from Solaris.I am linking project with options -m64 -lCstd -lrt -lsocket. m64 to force 64bits, it was necessary. Cstd, rt and socket due the fact that these libraries are used indirectly.
I am using Netbeans and compile remotely in Solaris 11
Compilation works fine.
Compilation command patterns is showed bellow:
g++ -m64 -c -g -I/home/f780333/paineldaemon/lib/indra_clib/include -I/home/f780333/paineldaemon/lib/instantclient_11_2/sdk/include -std=c++98 -MMD -MP -MF "build/Debug/GNU-Solaris-Sparc/main.o.d" -o build/Debug/GNU-Solaris-Sparc/main.o main.cpp
/home/f780333/paineldaemon/lib/indra_clib/include is a folder with a static library used by program. This library is mine and is necessary for project.
/home/f780333/paineldaemon/lib/instantclient_11_2/sdk/include is a folder from instantclient sdk, that includes *.h from OCCI.
But when linkage process starts, all head pain starts too:
(first) Linkage command:
g++ -o <all files here> -L/home/f780333/paineldaemon/lib/sun -L/home/f780333/paineldaemon/lib -L/home/f780333/paineldaemon/lib/instantclient_11_2 -R'/home/f780333/paineldaemon/lib/sun' -R'/home/f780333/paineldaemon/lib' -R'/home/f780333/paineldaemon/lib/instantclient_11_2' -lclntsh -locci /home/f780333/paineldaemon/lib/libindra_clib.a -m64 -lCstd -lrt -lsocket
And finally the linker ERROR MESSAGE:
Undefined first referenced
symbol in file
oracle::occi::Date::~Date() build/Debug/GNU-Solaris-Sparc/MessageBuilderATM.o
oracle::occi::Date::Date() build/Debug/GNU-Solaris-Sparc/MessageBuilderATM.o
oracle::occi::Number::operator=(oracle::occi::Number const&) build/Debug/GNU-Solaris-Sparc/MessageBuilderATM.o
oracle::occi::Number::Number(double) build/Debug/GNU-Solaris-Sparc/MessageBuilder.o
oracle::occi::Number::Number(long) build/Debug/GNU-Solaris-Sparc/MessageBuilder.o
oracle::occi::Number::Number() build/Debug/GNU-Solaris-Sparc/MessageBuilderATM.o
oracle::occi::Number::~Number() build/Debug/GNU-Solaris-Sparc/MessageBuilderATM.o
oracle::occi::Environment::createEnvironment(oracle::occi::Environment::Mode, void*, void* (*)(void*, unsigned long), void* (*)(void*, void*, unsigned long), void (*)(void*, void*)) build/Debug/GNU-Solaris-Sparc/DatabaseOperation.o
oracle::occi::Date::operator=(oracle::occi::Date const&) build/Debug/GNU-Solaris-Sparc/MessageBuilderATM.o
oracle::occi::Environment::terminateEnvironment(oracle::occi::Environment*) build/Debug/GNU-Solaris-Sparc/DatabaseOperation.o
oracle::occi::Date::Date(oracle::occi::Environment const*, int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) build/Debug/GNU-Solaris-Sparc/MessageBuilder.o
ld: fatal: symbol referencing errors
collect2: error: ld returned 1 exit status
gmake[2]: *** [dist/Debug/GNU-Solaris-Sparc/paineldaemon] Error 1
gmake[2]: Leaving directory `/home/f780333/.netbeans/remote/172.16.160.172/sylvia-Linux-x86_64/home/eduardo/Indra/Cartoes/repo/paineldaemon'
gmake[1]: *** [.build-conf] Error 2
gmake[1]: Leaving directory `/home/f780333/.netbeans/remote/172.16.160.172/sylvia-Linux-x86_64/home/eduardo/Indra/Cartoes/repo/paineldaemon'
gmake: *** [.build-impl] Error 2
I am crazy with this problem, any help will be much apreciate.
In my experience, OCCI has always been built for Solaris by using the Solaris Studio compiler.
You can't link an executable that uses CC-built code using g++, unless you can somehow coerce g++ to link in both the C++ run time libraries libCrun.so and libCstd.so along with the proper C++ run-time startup code, the same as Solaris Studio's CC does. That's probably not impossible, but it would be easier to just invoke ld directly and link the binary yourself.
And you can't compile C++ source code with g++ to match the name-mangling scheme used by Solaris Studio CC. (unless the code was built with a later version of CC and it used command-line arguments to produce g++-compatible name-mangling, among many other compatibility requirements, which in my experience OCCI never has been...)
In short, you need to use Solaris Studio's CC compiler to use OCCI on Solaris.

C++ compiler cannot find Boost libraries even after installing them

While compiling few test applications, I get the following error:
g++: error: −lboost_system: No such file or directory
g++: error: −lboost_filesystem: No such file or directory
while running the following command:
g++ -I/usr/include/boost/ -L/usr/lib/x86_64-linux-gnu/ aescuda.cpp -o test.o −lboost_system −lboost_filesystem
The libraries are installed and present in location as shown below:
<prompt>$ ll /usr/lib/x86_64-linux-gnu/libboost_system.*
-rw-r--r-- 1 root root 49178 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_system.a
lrwxrwxrwx 1 root root 25 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_system.so -> libboost_system.so.1.54.0
-rw-r--r-- 1 root root 14536 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_system.so.1.54.0
<prompt>$ ll /usr/lib/x86_64-linux-gnu/libboost_filesystem.*
-rw-r--r-- 1 root root 217628 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_filesystem.a
lrwxrwxrwx 1 root root 29 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_filesystem.so -> libboost_filesystem.so.1.54.0
-rw-r--r-- 1 root root 88936 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.54.0
Can anyone suggest where am I going wrong :(
You have a wrong character in front of the l:
−lboost_system
It should be an ASCII hyphen:
-lboost_system
This causes the compiler driver to treat the whole string as an input file name (which obviously does not exist, hence the No such file or directory error), and not as an option to be passed to the linker.
(Perhaps consider switching the terminal font.)

Eclipse CDT Post-Build commands error

I have a C++ project and I´m using Eclipse CDT 3.8.1 as the IDE tool, with a workspace of 5 different projects...
One of my projects is a shared library, and at the end of compilation I want to copy its code to a test/bin directory for testing.
I´ve gone to Project Properties -> C/C++ Build -> Settings -> Build Steps and at "Post-build steps", "Command", I´ve added:
cp *.so ../../../bin
(OBS: ../../../bin is the correct path from the Debug folder - I´ve checked already).
What happens is that I get the following error on post build:
cp *.so ../../../bin
cp: cannot stat ‘*.so’: No such file or directory
I said: ok, this may be a permission problem, so I changed the post commands to:
whoami;ls -al; ls *.so;
And I got on Eclipse console:
whoami
aeidev
ls -al
total 264
drwxrwxr-x 3 aeidev aeidev 4096 Apr 25 15:55 .
drwxrwxr-x 5 aeidev aeidev 4096 Apr 22 16:27 ..
-rwxrwxr-x 1 aeidev aeidev 242556 Apr 25 15:55 libaeirtuaccess.so
-rw-rw-r-- 1 aeidev aeidev 1763 Apr 23 20:47 makefile
-rw-rw-r-- 1 aeidev aeidev 245 Apr 23 20:46 objects.mk
-rw-rw-r-- 1 aeidev aeidev 526 Apr 23 20:47 sources.mk
drwxrwxr-x 2 aeidev aeidev 4096 Apr 25 15:41 src
ls *.so
15:55:11 Build Finished (took 1s.80ms)
And them I changed again to ls *.so and I got:
ls -al *.so
ls: cannot access *.so: No such file or directory
15:57:50 Build Finished (took 715ms)
It´s a very strange behaviour. In the same workspace I have a different shared library and the original cp *.so works fine...
Any ideas of what´s going on here ?
Is it a known Eclipse bug ?
Thanks for helping...
I believe the commands are not executed in a shell by default, so wildcards are not evaluated. Try executing like /bin/sh -c 'cp *.so ../../../bin/'. Also you should use Eclipse's built-in variables to copy to the desired path.

g++ link to shared library not being compiled

I have these shared library files in /usr/local/lib:
libopenbabel.so
libopenbabel.so.4
libopenbabel.so.4.0.2
libopenbabel.so is actually a link to libopenbabel.so.4 and libopenbabel.so.4 is actually a link to libopenbabel.so.4.0.2
when I compile my file with this command:
g++ test.cpp -L/usr/local/lib -lopenbabel
and then try to run a.out, I get this error:
./a.out: error while loading shared libraries: libopenbabel.so.4: cannot open shared object file: No such file or directory
Implying that the compiler is finding libopenbabel.so but running into an error when following that link to libopenbabel.so.4 which is in the exact same directory. Any ideas on why this is happening / how I can fix it?
Output of ls -l in /usr/local/lib:
total 33772
drwxr-xr-x 7 root root 4096 Mar 22 01:24 .
drwxr-xr-x 10 root root 4096 Aug 20 2013 ..
drwxr-xr-x 3 root root 4096 Mar 21 23:45 cmake
lrwxrwxrwx 1 root root 13 Mar 21 23:45 libinchi.so -> libinchi.so.0
lrwxrwxrwx 1 root root 17 Mar 21 23:45 libinchi.so.0 -> libinchi.so.0.4.1
-rw-r--r-- 1 root root 3315565 Mar 22 01:04 libinchi.so.0.4.1
lrwxrwxrwx 1 root root 17 Mar 21 23:45 libopenbabel.so -> libopenbabel.so.4
lrwxrwxrwx 1 root root 21 Mar 21 23:45 libopenbabel.so.4 -> libopenbabel.so.4.0.2
-rw-r--r-- 1 root root 31232420 Mar 22 01:04 libopenbabel.so.4.0.2
drwxr-xr-x 3 root root 4096 Mar 21 23:45 openbabel
drwxr-xr-x 2 root root 4096 Mar 22 01:24 pkgconfig
drwxrwsr-x 4 root staff 4096 Mar 3 12:57 python2.7
drwxrwsr-x 3 root staff 4096 Dec 22 18:25 python3.2
Either set your LD_LIBRARY_PATH environment variable to contain /usr/local/lib or add /usr/local/lib to /etc/ld.so.conf and run ldconfig as root.
Also, run ldd a.out to check that dynamic linking works well on your app.
Read ld-linux(8), ldconfig(8), ldd(1)