undefined reference to `sqlcxt' - c

Trying to compile some C code (a simple select * from dual with oracle (11g) db connection on Linux, generated from .pc thru proc command) through the gcc command and I always get an error.
undefined reference to 'sqlcxt'
I tried to link to libraries I saw on different forums around the web, but got nothing (error still occurs):
gcc -o proc_test proc_test.c -L$ORACLE_HOME/lib/libclntsh.so
and I still get
/tmp/ccAW4Imj.o: In function `main':
proc_test.c:(.text+0x3ea): undefined reference to `sqlcxt'
proc_test.c:(.text+0x57c): undefined reference to `sqlcxt'
proc_test.c:(.text+0x60d): undefined reference to `sqlcxt'
collect2: ld returned 1 exit status
Can anyone help with that?

The answer is:
gcc -o proc_test proc_test.c -L$ORACLE_HOME/lib -lclntsh -m32
I just needed to put -m32 cause libs and linux have different bits

Related

Issue with linking libraries built with gnat

When trying to build some test cases (just programs written in Ada), I get the following error:
gcc -c -shared decimaltests.adb
gnatbind -x decimaltests.ali
gnatlink decimaltests.ali -lGenerics -lNumerics -lTesting
/usr/bin/ld: decimaltests: hidden symbol `_Unwind_Resume' in
/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1/libgcc_eh.a(unwind-dw2.o) is referenced by DSO
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
gnatlink: error when calling /usr/bin/gcc
gnatmake: *** link failed.
I'm building them with gnatmake -shared *.ad{b,s} -largs -lGenerics -lNumerics -lTesting Clearly this isn't a problem with building the sources, but just to further confirm that, I copied the sources into this directory and built using gnatmake -shared *.ad{b,s} which built the tests just fine.
The dependent libraries are built and installed into a path gnat searches through. It doesn't seem to be an issue of not finding those. Not sure what's going on here.
All the libraries are built with gnatmake -O2 -fPIC -shared *.ad{b,s} as well as any relevant library dependencies. All libraries that depend on these can still be built. It's only even programs that depend on the libraries that throw this error, and always the same error.
Update: Building the libraries using gprbuild and then installing them with gprinstall seems to work similarly, except now the error is as follows:
decimaltests.o: In function `_ada_decimaltests':
decimaltests.adb:(.text+0x43): undefined reference to `testing__start'
decimaltests.adb:(.text+0x4a): undefined reference to
`generics__testing__default_tolerance'
decimaltests.adb:(.text+0x9e): undefined reference to
`generics__testing__default_tolerance'
decimaltests.adb:(.text+0x108): undefined reference to
`generics__testing__default_tolerance'
decimaltests.adb:(.text+0x172): undefined reference to
`generics__testing__default_tolerance'
decimaltests.adb:(.text+0x1dc): undefined reference to
`generics__testing__default_tolerance'
decimaltests.o:decimaltests.adb:(.text+0x23f): more undefined references to
`generics__testing__default_tolerance' follow
decimaltests.o: In function `_ada_decimaltests':
decimaltests.adb:(.text+0x14f5): undefined reference to `testing__stop'
/usr/lib/numerics//libNumerics.so: undefined reference to
`generics__testing__not_started#SYMS'
/usr/lib/numerics//libNumerics.so: undefined reference to
`generics__testing__pass#SYMS'
/usr/lib/numerics//libNumerics.so: undefined reference to
`generics__testing__fail#SYMS'
collect2: error: ld returned 1 exit status
gprbuild: link of decimaltests.adb failed
So I looked through the symbols table for both build methods and noticed, in both cases, the symbol most definitely exists, but the reference to it seems to be the wrong location. I'll try building on different platforms/compilers and update again if anything relevant comes up.
Both processes correctly build the libraries and test programs, and the test programs run properly, on different platforms. To further confirm that this is a bug, I've installed a different GCC toolchain and repeated the builds under the original platform, and this problem did not arise. I'll be filing a bug report.

libcurl curl/curl.h No such file or Directory Win xp 32 MinGW

I have been searching for a couple of hours and found several threads with the same problem and tried all their suggestions.
My curl.h is in C:\MinGW\msys\1.0\curl-7.29.0\include\curl and I've included it at compile time but for some reason gcc claims it can't find it:
gcc -o curl.exe curl.c -IC:/MinGW/msys/1.0/local/ -IC:/MinGW/msys/1.0/curl-7.29.0/lib/.libs/ -IC:/MinGW/msys/1.0/curl-7.29.0/include/curl -IC:/MinGW/msys/1.0/OpenSSL-Win32/ -lcurl -lws2_32
and the result:
curl.c:4:32: fatal error: curl/curl.h: No such file or directory
UPDATE: (With the suggestion from H2CO3)
$ gcc -o curl.exe curl.c -IC:/MinGW/msys/1.0/local -IC:/MinGW/msys/1.0/curl-7.29.0/lib/.libs/ -IC:/MinGW/msys/1.0/curl-7.29.0/include/ -IC:/MinGW/msys/1.0/OpenSSL-Win32/include/ -lws2_32
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0xa8): undefined reference to `_imp__curl_global_init'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0xe6): undefined reference to `_imp__curl_formadd'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x124): undefined reference to `_imp__curl_formadd'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x162): undefined reference to `_imp__curl_formadd'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x169): undefined reference to `_imp__curl_easy_init'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x183): undefined reference to `_imp__curl_slist_append'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x1b8): undefined reference to `_imp__curl_easy_setopt'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x211): undefined reference to `_imp__curl_easy_setopt'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x237): undefined reference to `_imp__curl_easy_setopt'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x245): undefined reference to `_imp__curl_easy_perform'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x25e): undefined reference to `_imp__curl_easy_strerror'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x288): undefined reference to `_imp__curl_easy_cleanup'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x296): undefined reference to `_imp__curl_formfree'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x2a4): undefined reference to `_imp__curl_slist_free_all'
collect2: ld returned 1 exit status
If I try to compile with -lcurl it says ..... ld.exe: cannot find -lcurl is this because it can't find the dll?
You're including <curl/curl.h>, and not <curl.h>. So you have to tell the compiler to look for header files in the include directory, and not in include/curl:
gcc -IC:\MinGW\msys\1.0\curl-7.29.0\include etc. etc.
This might be beyond the scope of what you're doing, but, I found it best to install a version of cURL(libcurl) into the MinGW/MSYS environment. After installed, any program can be compiled to use it with the typical <curl/curl.h> and -lcurl conventions since it's installed where GCC would expect it. I documented my process here.

I can't compile this code of mongoose web server's sample example

Short Intro :- (GCC version 4.6.3, OS-Ubuntu 12.04 ,working around mongoose web server program so when I run "make" command to compile and install mongoose , it has done the task fine ).
[Part 1 of question]
This question is in reference to this post on stackowerflow.
mongoose web server helloworld program
Valenok has answered on this post by giving a link to hello sample program.
basically, I am trying to compile the sample hello program code given on this link :-
http://code.google.com/p/mongoose/source/browse/examples/hello.c
and put this code in already compiled directory of mongoose.(directory has mongoose.h file)
Following is command line output for my compilation of hello program.
akshay#akshay-Inspiron-N5010:~$ gcc mongoose/hello.c -o mongoose/hello
/tmp/ccroC5Z6.o: In function `callback':
hello.c:(.text+0x32): undefined reference to `mg_get_request_info'
hello.c:(.text+0x96): undefined reference to `mg_printf'
/tmp/ccroC5Z6.o: In function `main':
hello.c:(.text+0xee): undefined reference to `mg_start'
hello.c:(.text+0x103): undefined reference to `mg_stop'
collect2: ld returned 1 exit status
akshay#akshay-Inspiron-N5010:~$
[Part 2 of question]
Now , I find implementations of mg_stop , mg_start,mg_printf and mg_get_request_info in mongoose.c file , so I compile mongoose.c file with -c option as :
gcc -c -o mongoose.o mongoose.c
I think my question is similar to :-
undefined reference to function declared in *.h file
but then when I link libmongoose.so with -L option on gcc I get following errors:-
(libmongoose.so is present in same directory ,my cwd)
akshay#akshay-Inspiron-N5010:~/mongoose$ gcc -L libmongoose.so -o hello hello.o mongoose.o
mongoose.o: In function `mg_start_thread':
mongoose.c:(.text+0x1369): undefined reference to `pthread_create'
mongoose.o: In function `load_dll':
mongoose.c:(.text+0xa955): undefined reference to `dlopen'
mongoose.c:(.text+0xa9b4): undefined reference to `dlsym'
collect2: ld returned 1 exit status
also , I continue to get above ^^ errors when I compile without using libmongoose.so
[EDIT] : added -pthread option on gcc, still shows errors :-
mongoose.o: In function load_dll':
mongoose.c:(.text+0xa955): undefined reference todlopen'
mongoose.c:(.text+0xa9b4): undefined reference to `dlsym'
collect2: ld returned 1 exit status
For part 1 and part 2 of my question : I want to get rid of these errors and successfully run hello.c program sample successfully.
Thanks in advance .
The -L option is not used for linking against a library, it's used for specifying a search path for dynamic libraries. To link against a specific library, use -l. However, you don't need to link against both of mongoose.o and libmongoose.so, either one is sufficient.
On Linux, you also have to link against the pthread and the dynamic loading library as well, because despite being part of the C standard library, they're not present in libc.so. One more thing to pay attention to is that recent versions of binutils (specifically, of ld) require that the libraries and object files be specified in the order the symbols depend on each other, i. e. libraries must go to the end of the command line.
All in all, use one of the following commands:
gcc -o hello hello.o mongoose.o -ldl -lpthread
or
gcc -L. -o hello hello.o -lmongoose -ldl -lpthread

program links properly on school machine, but not on personal one: undefined reference to log

I can ssh to my schools Ubuntu 11.04 server where I have to submit my code and this links fine:
ME#SCHOOL:~/309/project2$ make
gcc -lm treesort.c -o treesort
ME#SCHOOL:~/309/project2$
My local machine is running Ubuntu 12.04 and here is the compiler output for the same code, but using the NetBeans makefile:
gcc -lm -o dist/Release/GNU-Linux-x86/treesort build/Release/GNU-Linux-x86/sortFns.o build/Release/GNU-Linux-x86/treesort.o
build/Release/GNU-Linux-x86/treesort.o: In function `processargs':
treesort.c:(.text+0x144): undefined reference to `log'
collect2: ld returned 1 exit status
Using the command line on my local machine with the same code and makefile from the first example:
ME#MYCOMPUTER:~/Documents/CSCI/309/project2$ make
gcc -lm treesort.c -o treesort
/tmp/ccY5GqF1.o: In function `processargs':
treesort.c:(.text+0x2b5): undefined reference to `log'
collect2: ld returned 1 exit status
make: *** [all] Error 1
ME#MYCOMPUTER:~/Documents/CSCI/309/project2$
This is really quite irritating, and I can't figure out why it works on the server and not on my local machine. I found this question, but it didn't help.
Put -lm at the end of the link line. The order of sources,objects and (archive) libraries on the link line matters, and yours is wrong.
If putting -lm at the end of the link line doesn't help, you have some bogus library called libm.{a,so} somewhere on your system, and you should figure out where it came from, and get rid of it.
You cam find out which libm your linker is finding with gcc -Wl,-t ...

Protobuf-C Compilation Issue

I'm feeling a bit thick, but when I run through even basic examples provided on http://code.google.com/p/protobuf-c/wiki/Examples, I keep getting the following build errors:
/tmp/cc19catp.o: In function `main':
packit.c:(.text+0x13): undefined reference to `amessage__descriptor'
packit.c:(.text+0xb6): undefined reference to `amessage__get_packed_size'
packit.c:(.text+0xdb): undefined reference to `amessage__pack'
collect2: ld returned 1 exit status
I'm compiling with the following command:
gcc -o pack -lprotobuf-c packit.c
Anyone else have this problem? I feel I'm missing something basic.
gcc -o pack packit.c amessage.pb-c.c -lprotobuf-c
You must compile and link the proto-c-generated code.
Also, in general, when foo depends on bar, foo should precede bar in the linker command.

Resources