标签: static-linking

当使用-static时,如何让gcc/ld遍历许多'-l library'?

我想静态编译pdf2svg所以我将能够在稳定的Debian中使用最新版本.在./configure不给--enable-static选项,所以我在手动添加Makefile -static选项链接.

不幸的是,结果并不像我怀疑的那样.链接给了我很多undefined reference错误.经过一些谷歌搜索,我发现问题是由错误的顺序引起的-lsome_lib.Gcc链接器尝试在每个库中静态链接一次,当它第一次看到它时 - 信息和Stackoverflow问题:为什么链接库的顺序有时会导致GCC错误?.

是否有可能使链接器通过库列表进行多次传递?

c++ linker gcc ld static-linking

1
推荐指数
1
解决办法
1386
查看次数

如何在C++控制台应用程序中使用shell32.dll

我需要做的是获得ApplicationData路径,我在谷歌发现有一个叫做的功能

HRESULT SHGetFolderPath(
  __in   HWND hwndOwner,
  __in   int nFolder,
  __in   HANDLE hToken,
  __in   DWORD dwFlags,
  __out  LPTSTR pszPath
);
Run Code Online (Sandbox Code Playgroud)

但它存在于shell32.dll中.在C#中,我会做类似的事情

[DllImport]
static extern HRESULT SHGetFolderPath() and so on.
Run Code Online (Sandbox Code Playgroud)

在C++ Console应用程序中我需要做什么才能调用此API?也许,我可以使用LoadLibrary()?但是这样做的正确方法是什么?

我能以某种方式静态链接这个DLL作为我的exe的一部分吗?我正在使用Visual Studio 2010.

c++ linker static-linking

1
推荐指数
1
解决办法
4702
查看次数

Qt错误找不到-lQtCored collect2:ld返回1退出状态

当我在调试模式下运行程序时,我收到以下错误.

cannot find -lQtCored 
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

我可以在发布模式下正常运行程序.是因为我做了静态链接(我可以在没有Qt Creator的情况下运行我的可执行文件)?我在Windows上使用Qt Creator和Qt 4.7.0.

debugging qt qt-creator static-linking

1
推荐指数
1
解决办法
8712
查看次数

用G ++增强静态链接问题

我有一个应用程序,动态链接都可以,但是当我尝试使用静态链接进行编译时,我有以下错误.

我的应用程序使用boost线程,asio

错误:

/tmp/ccMj2fHI.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x237): undefined reference to `boost::system::get_system_category()'
test.cpp:(.text+0x243): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x24f): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x25b): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x267): undefined reference to `boost::system::get_system_category()'
/tmp/ccnCWj1O.o: In function `__static_initialization_and_destruction_0(int, int)':
AccountSe.cpp:(.text+0x507): undefined reference to `boost::system::get_system_category()'
AccountSe.cpp:(.text+0x513): undefined reference to `boost::system::get_generic_category()'
AccountSe.cpp:(.text+0x51f): undefined reference to `boost::system::get_generic_category()'
AccountSe.cpp:(.text+0x52b): undefined reference to `boost::system::get_generic_category()'
AccountSe.cpp:(.text+0x537): undefined reference to `boost::system::get_system_category()'
Run Code Online (Sandbox Code Playgroud)

所有源文件都有类似的错误.

编译命令行:

g ++ -L/usr/lib/-lboost_system -lboost_thread -o newserver -static /usr/lib/libboost_thread.a /usr/lib/libboost_system.a stdafx.cpp test.cpp AccountSe.cpp ... -lpthread -std …

c++ boost g++ undefined-reference static-linking

1
推荐指数
1
解决办法
3222
查看次数

Delphi以静态或动态方式链接到windows dll

我知道在加载时隐式链接到库可能会导致性能提升,因此我想知道在编译时以这种方式链接是否是一种好的做法,从而增加可执行文件大小(不可否认,这只是边际)与明确链接相比在运行时.我的问题是,当链接到位于System32中的Microsoft Windows DLL文件时,在加载时链接是否"更好",因为您可以确定库存在或遵循显式方法?

使用的语言是Delphi(pascal),有问题的库是WTsAPI32.dll - 终端服务.

编辑:正如所指出的那样 - 我选择的语言不正确并且已经修改.另外,由于在Unix中只有每一个与库有很多链接,我对可执行文件大小的评论可以省略,我当时认为我实际上是指静态链接将库代码捆绑到可执行文件中,我现在意识到这一点使用dll文件时是不可能的(DUH!).谢谢大家.

windows delphi dll dynamic-linking static-linking

1
推荐指数
1
解决办法
3053
查看次数

make 编译失败,未定义对 `EVP_DigestUpdate 的引用

我正在尝试在我的 ubuntu 13:04 上安装一个开源项目,但 make 过程在名为updateDB.c的类中的方法上失败。在编译期间,我有这个错误:

updateDB.o: In function `update_cache_hash':
/usr/local/src/bgpinspect-0.5/src/updateDB.c:142: undefined reference to `EVP_DigestUpdate'
/usr/local/src/bgpinspect-0.5/src/updateDB.c:143: undefined reference to `EVP_DigestFinal_ex'
collect2: error: ld returned 1 exit status
make[1]: *** [BGPdb] Error 1
make[1]: Leaving directory `/usr/local/src/bgpinspect-0.5/src'
make: *** [all] Error 2
Run Code Online (Sandbox Code Playgroud)

这是失败的update_cache_hash方法:

static uint16_t update_cache_hash( char *buff, int size ) {
    unsigned char md_hash[EVP_MAX_MD_SIZE];
    unsigned int md_len;
    uint16_t hash;

    EVP_DigestUpdate(&global_table.ctx, buff, size );
    EVP_DigestFinal_ex(&global_table.ctx, md_hash, &md_len);

    if ( md_len < 2 ) {
        ps_log( PS_LOG_ERROR, "EVP_DigestFinal_ex …
Run Code Online (Sandbox Code Playgroud)

c gcc makefile dynamic-linking static-linking

1
推荐指数
1
解决办法
1万
查看次数

无法链接到BFD

我想在我的项目中包含这个文件:http://cairo.sourcearchive.com/documentation/1.9.4/backtrace-symbols_8c-source.html

但它需要与BFD链接.我有两个binutilsbinutils-devel安装.我已经尝试过连接-lbfd以及直接连接/usr/lib64/libbfd.so/usr/lib64/libbfd.a(两者都存在).我也试图寻找pkg-config,看看是否有我应该使用不同的标志,但目前还BFD或没有提及binutilspkg-config.

无论我尝试过什么,我都会遇到以下错误:

undefined reference to 'bfd_init'
undefined reference to 'bfd_openr'
undefined reference to 'bfd_check_format'
undefined reference to 'bfd_checkformat_matches'
undefined reference to 'bfd_close'
undefined reference to 'bfd_map_over_sections'
Run Code Online (Sandbox Code Playgroud)

首先,我正在编译我的记录器和backtrace-symbols.c上面链接的文件(因为记录器是我打算用它来打印痕迹的地方).然后我将这两个目标文件一起链接到一个组合的目标文件中:

CC = clang
CFLAGS = -g -Wall -c
SOURCE = simplog.c
OBJ = simplog.o, simplog-temp.o, backtrace-symbols.o

all:
    $(CC) $(CFLAGS) $(SOURCE); mv simplog.o simplog-temp.o; \
    $(CC) -ansi $(CFLAGS) backtrace-symbols.c; \
    ld -r …
Run Code Online (Sandbox Code Playgroud)

c linker pkg-config dynamic-linking static-linking

1
推荐指数
1
解决办法
1503
查看次数

使用libcef_static.lib静态编译Chromium-Embedded 3项目

我从CEF Builds网站下载了CEF 3.2272.2029 .

编译好了.

然后根据CEF链接不同的运行时库我试图编译cefsimple示例libcef_static.lib(之前当然在编译指令中编译它).

所以,我更换输入库在Visual Studio:删除libcef.liblibcef_dll_wrapper.lib添加libcef_static.lib.然后出现了许多依赖项(error LNK2001: unresolved external symbol).

我在chromium\src\out\Release\obj子目录中的*.lib文件中搜索符号,添加它们,但是有很多它们可以找到所有依赖项.

因此,我搜索所有*.lib文件,只需将它们添加到链接器输入参数.但我不知道导入libs的顺序.

有没有简单的方法或教程以正确的顺序添加所有必要的依赖项来编译应用程序libcef_static.lib

c++ static-linking chromium-embedded

1
推荐指数
1
解决办法
2207
查看次数

为什么链接器会尝试链接到我从未告诉它链接到的文件?

我收到链接器错误,指示链接器无法打开文件(静态库),因此失败.我正在非常困难地排除此错误,因为我从未告诉链接器链接到它无法打开的文件.

我告诉链接器链接到几个静态库.我链接的许多库都是wxWidgets静态库.我不需要来自wxWidgets的所有模块,因此有一些我链接到的和许多我不是.链接器无法打开的文件是'wxbase31ud_net.lib'.就像我说的那样,该文件不在我链接的库中.我的直接想法是,这种依赖性是以某种方式隐式引入的,可能是我链接到的一个wxwidgets库.我不认为静态链接是这样工作的,但我没有任何其他想法.我一直在研究这种可能性,但我没有发现任何迹象表明情况.

  • 我将构建输出详细程度设置为最大值,并且在报告错误之前从未提及过'wxbase31ud_net.lib'.
  • 我在我的cmake项目中确认有问题的文件从未从FindWxWidgets模块传回给我,并且从未在与目标关联的任何文件列表中引用.
  • 我浏览了整个项目目录,发现在任何地方都没有引用该文件,包括cmake生成的项目文件(visual studio项目文件).

什么可能导致链接器尝试打开此文件?

编辑:另外,要清楚,我看到的错误是LNK1104

linker wxwidgets static-libraries static-linking visual-c++

1
推荐指数
1
解决办法
111
查看次数

Visual Studio 2015社区ZeroMQ静态库链接错误

我试图在Visual Studio 2015中使用ZeroMQ的静态库.我通过克隆git存储库生成它,将fd.hpp中的windows.hpp include更改#include <windows.hpp>#include "windows.hpp",将libsodium放在正确的位置,然后批量构建所有内容vs2015解决方案.

在程序中我试图使用ZeroMQ,我包括ZeroMQ包含目录,包括ZeroMQ发布静态目录(libzmq\bin\Win32\Release\v140\static),添加了libzqm.lib作为附加依赖项,定义了ZMQ_STATIC和_CRT_SECURE_NO_WARNINGS对于我在程序中执行的其他一些操作,并将运行时库更改为多线程/ MT.

当我在这一点上尝试编译时,我得到以下错误:

1>------ Build started: Project: HttpServer, Configuration: Release Win32 ------
1>  main.cpp
1>libzmq.lib(zmq.obj) : error LNK2001: unresolved external symbol ___WSAFDIsSet@8
1>libzmq.lib(socket_poller.obj) : error LNK2001: unresolved external symbol ___WSAFDIsSet@8
1>libzmq.lib(select.obj) : error LNK2001: unresolved external symbol ___WSAFDIsSet@8
1>libzmq.lib(zmq.obj) : error LNK2001: unresolved external symbol __imp__select@20
1>libzmq.lib(socket_poller.obj) : error LNK2001: unresolved external symbol __imp__select@20
1>libzmq.lib(select.obj) : error LNK2001: unresolved external symbol __imp__select@20
1>libzmq.lib(signaler.obj) : error LNK2001: unresolved external …
Run Code Online (Sandbox Code Playgroud)

c++ static-libraries zeromq static-linking visual-studio-2015

1
推荐指数
1
解决办法
1656
查看次数