ar

Possible to use a .dll on Linux

我们两清 提交于 2019-12-03 05:59:55
Question: Is it possible to compile a program on linux using a .dll file? Where this is going: This .dll will be used to write a php extension to some proprietary software from a third party. Background and Research: I have been given a library called proprietary.lib . I was curious, as I have never seen the .lib extension before, so I typed: file proprietary.lib The output was: proprietary.lib: current ar archive I did some research and found that ar is more-or-less tar (and in fact, I guess tar has since replaced ar in most *nix environments). Upon inspecting the ar manpage, I saw the t

gcc编译生成静态及动态链接库步骤

北城以北 提交于 2019-12-02 18:25:57
这两天在看《Linux C程序设计大全》,吴岳编著,清华大学出版社。这本书是在一个培训机构看到的,在网上查了下该书的相关信息。从目录而言,该书涵盖了Linux下C程序设计的较多内容,包括C语言基础(主要讲解C语法结构)、C语言开发环境(主要介绍VIM使用、GCC使用、makefile编写、gdb使用)、Linux进程操作、Linux文件操作、Linux网络编程这几部分。阅读了该书几个小章节,总体而言,书的部分内容较充实,但是存在较多编辑错误,部分样例实际运行时与书中内容不符。 这里使用该书P192-P199的例子,总结下gcc编译静态及动态链接库的方法及步骤。 程序清单如下: test.c文件内容: int add(int a, int b) { return a + b; } int sub(int a, int b) { return a - b; } int mul(int a, int b) { return a * b; } int div(int a, int b) { return a / b; } test.h文件内容: #ifndef _TEST_H_ #define _TEST_H_ extern int add(int a, int b); extern int sub(int a, int b); extern int mul(int a, int b);

What's the order for gcc to link unresolved symbol in static library

こ雲淡風輕ζ 提交于 2019-12-02 02:18:37
When debug the function symbols conflicts problem, I find a strange behavior of gcc i couldn't understand, illustrate by the following sample code: main.c #include <stdio.h> int main() { b(); a(); } a.c #include <stdio.h> void a(void) { printf("func a in a\n"); } b.c #include <stdio.h> void a() { printf("func a in b\n"); } void b() { printf( "func b try to call a \n"); a(); } compile: gcc -c a.c gcc -c b.c ar -cr liba.a a.o ar -cr libb.a b.o gcc main.c liba.a libb.a execute: ./a.out func b try to call a func a in b func a in b My question is : Why calling function a in main function is a in b

Turn thin archive into normal one

雨燕双飞 提交于 2019-11-30 14:02:27
I'm building V8 , and by default it builds as a "thin" archive, where the .a files essentially just contain pointers to the object files on your filesystem instead of containing the object files themselves. See man ar for details. I want to be able to put this library in a central place so that other people can link to it, and it would be obviously much easier to provide a normal archive file instead of providing a gaggle of object files as well. How do I take the thin archives produced by the build and turn them into normal ones? I assume it would be as simple as enumerating the object files

Object files not properly added to archive on mac

为君一笑 提交于 2019-11-29 12:03:47
I am trying to build an archive from a collection of object files. I am doing this with ar -rs my_archive.a foo.o bar.o other_object_files.o . On a linux machine everything is fine but when I try the very same command on my mac it seems like only some object files are added. This results in undefined symbols corresponding to subroutines in, let's say, other_object_files.o . Moreover, if I try to manually link the object files that gave rise to undefined symbols, I can properly build the executable. That is ifort -o my_exec main.o other_object_files.o my_archive.a works fine. Am I missing some

Override weak symbols in static library

不羁的心 提交于 2019-11-29 06:52:01
I want to make a static .a library for my project from multiple sources, some of them define weak functions and others implements them. Let's say as example I have : lib1.c : void defaultHandler() { for(;;); } void myHandler() __attribute__((weak, alias ("defaultHandler"))); lib2.c : void myHandler() { /* do my stuff here */ } Then I want to put them into one single library, so that it seems transparent for the end application $ ar -r libhandlers.a lib1.o lib2.o But there is now 2 symbols myHandler in libhandlers : $ nm libhandlers.a | grep "myHandler" 00000001 W myHandler 00000581 T myHandler

Combining static libraries

核能气质少年 提交于 2019-11-28 17:39:11
Suppose I have three C static libraries say libColor.a which depends on *libRGB.*a which in turn depends on libPixel.a . The library libColor.a is said to depend on library libRGB.a since there are some references in libColor.a to some of symbols defined in libRGB.a . How do I combine all the above libraries to a new libNewColor.a which is independent? Independent means the new library should have all symbols defined. So while linking I just need to give -lNewColor . The size of the new library should be minimal i.e it should not contain any symbols in libRGB.a which is not used by libColor.a

Static library link issue with Mac OS X: symbol(s) not found for architecture x86_64

怎甘沉沦 提交于 2019-11-28 12:38:35
I'm trying to generate a static library and link it with an execution binary. This is a library function: #include <stdio.h> int hello() { return 10; } With these commands, I could get a static library. gcc -c io.c ar -crv libio.a io.o With lip -info , I checked it is x86_64 architecture. ar> lipo -info libio.a input file libio.a is not a fat file Non-fat file: libio.a is architecture: x86_64 This is the main function that uses the library. #include <stdio.h> extern int hello(); int main(int argc, char *argv[]) { printf("%d", hello()); } However, when I link the object with the static library,

Combining static libraries

瘦欲@ 提交于 2019-11-27 10:37:59
问题 Suppose I have three C static libraries say libColor.a which depends on *libRGB.*a which in turn depends on libPixel.a . The library libColor.a is said to depend on library libRGB.a since there are some references in libColor.a to some of symbols defined in libRGB.a . How do I combine all the above libraries to a new libNewColor.a which is independent? Independent means the new library should have all symbols defined. So while linking I just need to give -lNewColor . The size of the new

Linking static libraries to other static libraries

江枫思渺然 提交于 2019-11-26 00:31:33
问题 I have a small piece of code that depends on many static libraries (a_1-a_n). I\'d like to package up that code in a static library and make it available to other people. My static library, lets call it X, compiles fine. I\'ve created a simple sample program that uses a function from X, but when I try to link it to X, I get many errors about missing symbols from libraries a_1 - a_n. Is there a way that I can create a new static library, Y that contains X and all the functionality needed by X