Solved

link shared library with math function in C

Posted on 2014-09-07
9
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
9 Comments
 
LVL 45

Accepted Solution

by:
Kent Olsen 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 45

Expert Comment

by:Kent Olsen
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:Kent Olsen
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

635 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