473,660 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Statically linking a library problem...


Hi,

I'm trying to statically link a library I creat with
'ar rcs mylib.a .o files....'

If I link only the .o files with my .c file, I get no
compile error and the program runs fine. But if I link
it with the library I have archived, I get undefined
reference to the methods I'm calling from those .o files.
The mylib.a does contain all the .o files and I've
tried to link it with (or without) -L and even done
ranlib mylib.a but still no good. All files are under
a single directory.

I was wondering if someone could shed some light here.

Thanks
Nov 14 '05 #1
2 1454
ox*****@oxblood .cc writes:
I'm trying to statically link a library I creat with
'ar rcs mylib.a .o files....'


Your question is outside the domain of comp.lang.c, which discusses
only the standard C programming language, including the standard C
library. This is a remarkably narrow topic compared to what many
people expect.

For your convenience, the list below contains topics that are not
on-topic for comp.lang.c, and suggests newsgroups for you to explore
if you have questions about these topics. Please do observe proper
netiquette before posting to any of these newsgroups. In particular,
you should read the group's charter and FAQ, if any (FAQs are
available from www.faqs.org and other sources). If those fail to
answer your question then you should browse through at least two weeks
of recent articles to make sure that your question has not already
been answered.

* OS-specific questions, such as how to clear the screen,
access the network, list the files in a directory, or read
"piped" output from a subprocess. These questions should be
directed to OS-specific newsgroups, such as
comp.os.ms-windows.program mer.misc, comp.unix.progr ammer, or
comp.os.linux.d evelopment.apps .

* Compiler-specific questions, such as installation issues and
locations of header files. Ask about these in
compiler-specific newsgroups, such as gnu.gcc.help or
comp.os.ms-windows.program mer.misc. Questions about writing
compilers are appropriate in comp.compilers.

* Processor-specific questions, such as questions about
assembly and machine code. x86 questions are appropriate in
comp.lang.asm.x 86, embedded system processor questions may
be appropriate in comp.arch.embed ded.

* ABI-specific questions, such as how to interface assembly
code to C. These questions are both processor- and
OS-specific and should typically be asked in OS-specific
newsgroups.

* Algorithms, except questions about C implementations of
algorithms. "How do I implement algorithm X in C?" is not a
question about a C implementation of an algorithm, it is a
request for source code. Newsgroups comp.programmin g and
comp.theory may be appropriate.

* Making C interoperate with other languages. C has no
facilities for such interoperation. These questions should
be directed to system- or compiler-specific newsgroups. C++
has features for interoperating with C, so consider
comp.lang.c++ for such questions.

* The C standard, as opposed to standard C. Questions about
the C standard are best asked in comp.std.c.

* C++. Please do not post or cross-post questions about C++
to comp.lang.c. Ask C++ questions in C++ newsgroups, such
as comp.lang.c++ or comp.lang.c++.m oderated.

* Test posts. Please test in a newsgroup meant for testing,
such as alt.test.

news.groups.que stions is a good place to ask about the appropriate
newsgroup for a given topic.

--
Ben Pfaff
email: bl*@cs.stanford .edu
web: http://benpfaff.org
Nov 14 '05 #2
ox*****@oxblood .cc wrote:
Hi,

I'm trying to statically link a library I creat with
'ar rcs mylib.a .o files....'

If I link only the .o files with my .c file, I get no
compile error and the program runs fine. But if I link
it with the library I have archived, I get undefined
reference to the methods I'm calling from those .o files.
The mylib.a does contain all the .o files and I've
tried to link it with (or without) -L and even done
ranlib mylib.a but still no good. All files are under
a single directory.


Depends on the order ... e.g.

gcc mylib.a somefile.o -o test

is different than

gcc somefile.o mylib.a -o test

GCC will resolve depends left-to-right. E.g. Linked into "test" will be
all of the modules from mylib.a needed at that point (in the case of the
former no depends exist yet where in the latter they may).

Internally on most platforms the link would actually be

crt0.o $(YOURSTUFF) libc.a
crt0.o for instance depends on main() which should be located in one of
YOURSTUFF object files. YOURSTUFF is probably dependent on libc.a, etc,
etc..

Tom
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2350
by: LinuxN00b | last post by:
Hey, I have a problem linking Xerces-c (Apache's XMLParser) with my program. Here is a copy of my makefile. # CXX is for GNU make, CCC is for Solaris make # Define the default compiler to use for C++ programs as u++ CXX=g++
2
7245
by: | last post by:
Help! I'm new to c++, and am breaking my teeth on MS Visual C++ (bundled within Visual Studio .NET 2003). Am trying to link simple c++ code to fortran dlls created in Compaq Visual Fortran (v6.1). Posts concerning this topic are common, but none of the posted solutions I've tried work correctly with the above software. The linker can't seem to find the dll (reports 'unresolved external symbol __imp__IMSL_FUN@8'; IMSL_FUN.dll is the f77...
7
7386
by: Lee Crabtree | last post by:
I'm starting work on what will eventually be a very, very LARGE project. A lot of the project involves taking C/C++ class libraries and wrapping them with managed C++. I'd like to minimize the number of DLLs I have (because I'd like to keep my sanity). Is there some way to compile a managed C++ DLL into a C# DLL, or am I just stuck consolidating the managed C++ into a single DLL? Lee
8
2075
by: bonk | last post by:
Is it generally OK for an EXE that has MFC linked statically to load an use another DLL wich has MFC linked as shared DLL ? To be more specific: I have an EXE that links a lib. Let's call it mylib.lib. That Lib as well as the EXE have MFC linked statically. Then in a completely different project I have a regular DLL, wich is compiled with the /CLR switch and therefore needs the special CRT libs as
2
2471
by: google | last post by:
I statically link the Synopsys Milkyway C-API library ("MDA") into my C++ application. When my C++ application throws an exception, it seg faults instead. The details of my environment are: x86 (Pentium) CPU or AMD x86_64 (Opteron) Red Hat Enterprise Linux 3 OS gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-54) Also reproduced with gcc version 3.3.2
1
2355
by: ankur.cdac | last post by:
I have Sun WorkShop 6 update 1 C++ 5.2 2000/09/11 compiler running on SunOS 5.7 Generic_106541-08 sun4u sparc SUNW,Ultra-60 machine. i am using /opt/SUNWspro/bin//CC for building C++ code. I want to link a shared library libxyz.so to my binary satically, so that i may not need that at run time. i used -staticlib=xyz but its not working . Its saying that CC: Warning: illegal option xyz ignored I included the path in PATH and...
0
3976
by: xieml2007 | last post by:
Dear Madam or Sir, I encountered one problem which is quite similiar to the discussions launched at the web site: http://www.thescripts.com/forum/thread280324.html
36
3187
by: Martin Larsen | last post by:
Hi, When a PHP program links to a library using include or require (or their _once variations), is the library then linked dynamically or statically? While it might seem irrelevant from a technical point of view, the linking method is important when it comes to licencing issues as some licences, like GPL, differ between those kinds of linking when it comes to viewing the library as a derivative work of the main program.
12
34361
by: tvnaidu | last post by:
I am getting this link error, I am using mongoose web server with Linux, any idea?: mongoose.c:3114: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking mongoose.c:3081: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8754
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8542
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1740
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.