在编译和链接期间,.exp的用途是什么?.lib和.dll有什么区别?我知道将使用.lib,而在运行程序时将使用链接和.dll.但是.lib和.dll之间究竟有什么区别?
.lib文件不包含来自.dll文件的函数的代码吗?使用两个单独的文件需要什么?
请澄清.
我在mac上编写C++代码.编译时为什么会出现此错误?:
体系结构i386的未定义符号:"Log :: theString",引用自:libTest.a中的Log :: method(std :: string)(Log.o)ld:未找到体系结构i386 clang的符号:错误:链接器命令失败,退出代码为1(使用-v查看调用)
不确定我的代码是否错误或者我必须向Xcode添加其他标志.我当前的XCode配置是"静态库"项目的默认配置.
我的代码:
Log.h ------------
#include <iostream>
#include <string>
using namespace std;
class Log{
public:
static void method(string arg);
private:
static string theString ;
};
Run Code Online (Sandbox Code Playgroud)
Log.cpp ----
#include "Log.h"
#include <ostream>
void Log::method(string arg){
theString = "hola";
cout << theString << endl;
}
Run Code Online (Sandbox Code Playgroud)
我用测试代码调用'方法',这样:'Log :: method("asd"):'
谢谢你的帮助.
我正在尝试使用libtommath库.我在Ubuntu linux上使用NetBeans IDE作为我的项目.我已经下载并构建了库,我已经完成了'make install'以将生成的.a文件放入/ usr/lib /并将.h文件放入/ usr/include
它似乎是正确地找到文件(因为我不再得到这些错误,我在安装到/ usr目录之前做了这些错误).
但是,当我创建一个简单的main来调用mp_init(在库中)时,当我尝试创建项目时出现以下错误:
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
gcc -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.c
mkdir -p dist/Debug/GNU-Linux-x86
gcc -o dist/Debug/GNU-Linux-x86/cproj1 build/Debug/GNU-Linux-x86/main.o
build/Debug/GNU-Linux-x86/main.o: In function 'main':
/home/[[myusername]]/NetBeansProjects/CProj1/main.c:18: undefined reference to `mp_init'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/cproj1] Error 1
Run Code Online (Sandbox Code Playgroud)
因此,看起来链接器无法在库中找到该函数,但它就在那里,所以我只是不知道是什么原因造成的.
如果我直接输入gcc命令并跳过makefile,我会得到同样的错误,我也确保静态库也用gcc编译.
编辑添加:
如果我直接编译并使用-l或-L添加库,我会得到同样的错误:
$ gcc -l /usr/lib/libtommath.a main.c
/usr/bin/ld: cannot find -l/usr/lib/libtommath.a
collect2: ld returned 1 exit status
$ gcc -llibtommath.a main.c
/usr/bin/ld: cannot find -llibtommath.a …Run Code Online (Sandbox Code Playgroud) 我有一个链接到许多库的程序.g++默认情况下,即使存在相应的存档,也更喜欢链接到共享库.
如果存在静态存档,如何将此首选项更改为优先于静态存档而不是动态库?
注意,我使用了-static选项,但它试图找到所有库的静态存档,这不是我想要的.
我正在尝试将静态库链接到共享库,我收到了以下错误
/usr/bin/ld: ../../../libraries/log4cplus/liblog4cplus.a(fileappender.o): relocation R_X86_64_32S against `a local symbol' can not be used when making a shared object; recompile with -fPIC ../../../libraries/log4cplus/liblog4cplus.a: could not read symbols: Bad value collect2: ld returned 1 exit status
但这适用于32位机器而没有任何此类错误.我尝试-fPIC手动将标志添加到Makefile,但也没有解决问题
我-whole-archive按照这里的建议尝试了旗帜,但没有成功.
/usr/bin/ld: ../../../libraries/log4cplus/liblog4cplus.a(appenderattachableimpl.o): relocation R_X86_64_32S against `vtable for log4cplus::spi::AppenderAttachable' can not be used when making a shared object; recompile with -fPIC ../../../libraries/log4cplus/liblog4cplus.a(appenderattachableimpl.o): could not read symbols: Bad value collect2: ld returned 1 exit status
unzip log4cplus-1.1.0.zip./configure --enable-static=yes …我正在尝试链接到OS X上的静态库.我-static在gcc命令中使用了该标志,但是我收到以下错误消息:
ld_classic: can't locate file for: -lcrt0.o collect2: ld returned 1 exit status
我查看了手册页,它的内容如下:
除非所有库(包括libgcc.a)都已使用-static编译,否则此选项在Mac OS X上不起作用.由于既没有提供libSystem.dylib的静态版本也没有提供crt0.o,因此该选项对大多数人没用.
有没有其他方法可以链接到这个静态库?
我有一个第三方库,主要包含大量的static(.a)库文件.我可以将它编译成单个.a库文件,但我真的需要它作为单个.so共享库文件.
有没有办法将静态.a文件转换为共享.so文件?或者更一般地说,有一种很好的方法可以将大量静态.a文件与一些.o目标文件合并到一个.so文件中?
我正在尝试从类中创建一个静态库,但是当我尝试使用它时,我总是会遇到任何未定义引用的错误.我继续的方式是创建像这样的目标文件
g++ -c myClass.cpp -o myClass.o
Run Code Online (Sandbox Code Playgroud)
然后用它包装
ar rcs myClass.lib myClass.o
Run Code Online (Sandbox Code Playgroud)
有一些我通常会忽略这一点.我打赌这是符号的东西.感谢您的任何建议,我知道这很可能是我可以找到的东西,如果阅读一些教程,所以很抱歉再次困扰愚蠢的东西:)
myClass.h:
class myClass{
public:
myClass();
void function();
};
Run Code Online (Sandbox Code Playgroud)
myClass.cpp:
#include "myClass.h"
myClass::myClass(){}
void myClass::function(){}
Run Code Online (Sandbox Code Playgroud)
程序使用类:
#include "myClass.h"
int main(){
myClass mc;
mc.function();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
最后我像这样编译它:
g++ -o main.exe -L. -l myClass main.cpp
Run Code Online (Sandbox Code Playgroud)
错误只是经典:
C:\Users\RULERO~1\AppData\Local\Temp/ccwM3vLy.o:main.cpp:(.text+0x31): undefined
reference to `myClass::myClass()'
C:\Users\RULERO~1\AppData\Local\Temp/ccwM3vLy.o:main.cpp:(.text+0x3c): undefined
reference to `myClass::function()'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud) 我正试图在Microsoft Windows上理解这个LIB文件业务,我刚刚发现了一个发现 - 我希望 - 消除迄今为止阻止我清楚地掌握这个问题的混乱.也就是说,LIB文件不是他们的文件扩展名表明的那种文件.
:: cd "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib"
:: lib /nologo /list Ad1.Lib
obj\i386\activdbgid.obj
obj\i386\activscpid.obj
obj\i386\ad1exid.obj
obj\i386\dbgpropid.obj
obj\i386\dispexid.obj
:: lib /nologo /list oledb.lib
o:\winmain.obj.x86fre\enduser\…\oledb\uuid\objfre\i386\oledbiid.obj
o:\winmain.obj.x86fre\enduser\…\oledb\uuid\objfre\i386\oledbnewiid.obj
o:\winmain.obj.x86fre\enduser\…\oledb\uuid\objfre\i386\cmdtreeiid.obj
o:\winmain.obj.x86fre\enduser\…\oledb\uuid\objfre\i386\oledbdepiid.obj
:: lib /nologo /list AdvAPI32.Lib | sort | uniq -c
731 ADVAPI32.dll
Run Code Online (Sandbox Code Playgroud)
前两个示例包含目标文件(在lib.exe实用程序显示时显示为相对路径或绝对路径).但是,第三个示例仅包含对DLL的731个引用.(我想lib.exe这不是为了显示这种文件的更多有用信息.)
一些包含目标文件,它们是静态库.其他包含符号,它们是导入库.(这里有一个简短的解释.)
因此,静态库似乎是.aLinux 上文件的等价物,而DLL似乎映射到.soLinux 上的文件.(顺便说一下,导入库如何适应这个Windows/Linux等效图片?)
现在我想知道为什么会这样?为什么Microsoft决定为导入库提供与静态库相同的文件扩展名?(我理解,从历史上看,静态图书馆是第一位的,就像原始形式的生活先于更复杂的形式.)为什么他们不会说,好吧,这些是新的图书馆,他们应该被称为进口图书馆,他们应该承担文件扩展名.ILB(或其他)?
我是Android Studio的新手,我想为我的应用程序使用Volley库,但我无法在Android Studio中将源添加为库.
我在网上搜索但找不到任何东西.据说到处都是图书馆,但我不知道怎么做.
我从git存储库获得了截击源:
https://android.googlesource.com/platform/frameworks/volley
Run Code Online (Sandbox Code Playgroud)
但我不知道如何将它作为库添加到我的项目中.