Solved

link shared library with math function in C

Posted on 2014-09-07
9
211 Views
Last Modified: 2014-09-22
link shared library with math.h functions in C
I need command line example.

Generally for this:
http://chimera.labs.oreilly.com/books/1230000000393/ch15.html
0
Comment
Question by:Nusrat Nuriyev
  • 3
  • 3
  • 3
9 Comments
 
LVL 45

Accepted Solution

by:
Kdo earned 250 total points
ID: 40308715
Hi Nusrat,

It depends mostly on the tools that you're using.  The O/S, compiler, and linker.

If you're using GCC, it a command line option.

  gcc -l library ...

Just add "-l library" to the command line with the other options.  GCC will pass that to the linker.


Kent
0
 
LVL 5

Assisted Solution

by:Sapa
Sapa earned 250 total points
ID: 40308815
Try to use:

gcc -shared -o myfile.so myfile.c -lm

where  myfile,c is your source file, but myfie.so is the shared library you want to create
0
 

Author Comment

by:Nusrat Nuriyev
ID: 40335125
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 45

Expert Comment

by:Kdo
ID: 40335382
Hi Nusrat,

If you're trying to link a library to your compiled code, you don't need the -fPIC parameter.  -fPIC indicates that the code that you're compiling is to be inserted into a library for later use.  Note that -fPIC isn't needed for most C functions that are going to be placed in a library.


Kent
0
 

Author Comment

by:Nusrat Nuriyev
ID: 40335456
[root@localhost tmp]# gcc -shared -o libsample.so sample.c -lm
/bin/ld: /tmp/ccjQThFb.o: relocation R_X86_64_PC32 against undefined symbol `hypot@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status

Could you explain what does this mean? And where to read about this?
0
 
LVL 5

Expert Comment

by:Sapa
ID: 40335901
Just add -fPIC as suggested. Like:

gcc -shared -fPIC -o libsample.so sample.c -lm
0
 
LVL 5

Expert Comment

by:Sapa
ID: 40335905
PIC means Position Independent Code. This code has neither conditional nor unconditional jumps to fixed addresses and can be loaded (actually mapped) from arbitrary address. It is important for shared libraries because nobody knows during library linking the address where they be mapped to during programm execution.
0
 

Author Comment

by:Nusrat Nuriyev
ID: 40336035
Yes, I should add that, the question was what does this mean:
relocation R_X86_64_PC32 against undefined symbol `hypot@@GLIBC_2.2.5' can not be used when making a shared object;
0
 
LVL 45

Expert Comment

by:Kdo
ID: 40336554
Hi Nusrat,

The issue came about as systems expanded from 32 to 64 bits.  The high-level explanation is that the object in question isn't compatible with the module being created and is therefore considered undefined.  It's kind of like a C++ method void F1(int X) being undefined when the compiled program calls F1 ("string).

A 64-bit program linking to or via a 32-bit object could be disastrous as the other 32 bits are the 32-bits next to the stored object.  A read using the object is undefined.  A write of the object clobbers the object next to it.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question