我想在linux上编译一些我知道在OSX上编译的代码,但是我遇到了一些问题.
所有文件都有名为.h的头文件,所有文件都在同一目录下.我这样编译:
gcc *.c -std=c99 -lpthread
Run Code Online (Sandbox Code Playgroud)
虽然这段代码在OSX上编译,但我在Ubuntu安装上遇到了一堆奇怪的链接器错误.我错过了一些编译器选项吗?它是一个默认的Ubuntu服务器安装,带有附加软件包gcc并build-essential已安装.
In file included from errorLogger.h:24:0,
from configParser.h:17,
from configParser.c:9:
signalHandling.h:24:18: error: unknown type name ‘sigset_t’
configParser.c: In function ‘parseConfigFile’:
configParser.c:114:5: warning: implicit declaration of function ‘getline’ [-Wimplicit-function-declaration]
In file included from errorLogger.h:24:0,
from global.h:18,
from connection.h:19,
from connection.c:10:
signalHandling.h:24:18: error: unknown type name ‘sigset_t’
connection.c: In function ‘createConnectionQueue’:
connection.c:189:28: warning: assignment makes integer from pointer without a cast [enabled by default]
In file included from errorLogger.h:24:0,
from database.h:16,
from …Run Code Online (Sandbox Code Playgroud) 我觉得我在这里错过了一些非常简单的东西。我想玩一下 clang,所以作为一个起点,我遵循了这个视频中的代码示例,大约 3:40。代码如下:
#include "clang-c/Index.h" // Note: These two lines were
#include <stdio.h> // omitted from the video slides
int main(int argc, char *argv[])
{
CXIndex Index = clang_createIndex(0, 0);
CXTranslationUnit TU = clang_parseTranslationUnit(Index, 0, argv, argc, 0, 0, CXTranslationUnit_None);
for (unsigned I = 0, N = clang_getNumDiagnostics(TU); I != N; ++I)
{
CXDiagnostic Diag = clang_getDiagnostic(TU, I);
CXString String = clang_formatDiagnostic(Diag, clang_defaultDiagnosticDisplayOptions());
fprintf(stderr, "%s\n", clang_getCString(String));
clang_disposeString(String);
}
clang_disposeTranslationUnit(TU);
clang_disposeIndex(Index);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在视频中,他没有声明他省略了这两个#include指令。我想我在上面的例子中正确填写了这些。他还省略了文件的编译和链接方式,这是我遇到问题的部分。按照 …
我刚刚在新的ubuntu 12.10服务器上编译了chironfs,并收到以下错误:
gcc -Wall -W -Wmissing-prototypes -g -O2 -DFUSE_USE_VERSION=25 -D_FILE_OFFSET_BITS=64 -I/usr/local/include -g -O2 -lm -lfuse -o chironfs chironfs.o chiron-conf.o chirondbg.o chironfn.o
chironfs.o: In function `chiron_init':
/root/chironfs-1.1.1/src/chironfs.c:2000: undefined reference to `pthread_create'
chironfs.o: In function `get_rights_by_name':
/root/chironfs-1.1.1/src/chironfs.c:452: undefined reference to `fuse_get_context'
Run Code Online (Sandbox Code Playgroud)
pthread错误告诉我-lpthread丢失,但是保险丝错误有点奇怪,因为正在使用-lfuse
我在这里找到了建议将库放在目标文件之后的解决方案
所以我删除了-lfuse并在行的最后添加了-lfuse -lpthread
现在它可以编译而没有错误,看来这就是应该的样子:目标文件后的库
我的问题是:为什么参数顺序与gcc / ld有关?我tough gcc像其他所有应用程序一样解析参数,并且可以将必要的参数转发给ld或此类
一般而言:任何人都知道gcc参数排序的事实或提示,也许还有些关于为什么需要这种方式的背景信息?
谢谢
我想将Octave转换为使用CuBLAS进行矩阵乘法.此视频似乎表明这就像键入28个字符一样简单:
在实践中,它比这复杂一点.有谁知道在这个视频编译中进行修改必须做哪些额外的工作?
这是我正在尝试的方法
在dMatrix.cc中添加
#include <cublas.h>
在dMatrix.cc中更改所有出现的(保留案例)
dgemm
至
cublas_dgemm
在我的构建终端设置中
export CC=nvcc
export CFLAGS="-lcublas -lcudart"
export CPPFLAGS="-I/usr/local/cuda/include"
export LDFLAGS="-L/usr/local/cuda/lib64"
Run Code Online (Sandbox Code Playgroud)
我收到的错误是:
libtool: link: g++ -I/usr/include/freetype2 -Wall -W -Wshadow -Wold-style-cast
-Wformat -Wpointer-arith -Wwrite-strings -Wcast-align -Wcast-qual -g -O2
-o .libs/octave octave-main.o -L/usr/local/cuda/lib64
../libgui/.libs/liboctgui.so ../libinterp/.libs/liboctinterp.so
../liboctave/.libs/liboctave.so -lutil -lm -lpthread -Wl,-rpath
-Wl,/usr/local/lib/octave/3.7.5
../liboctave/.libs/liboctave.so: undefined reference to `cublas_dgemm_'
Run Code Online (Sandbox Code Playgroud) 只是一个简单的问题,但我无法\xe2\x80\x99t 在任何地方找到答案。将所有目标文件放入存档时,如何指示 clang++ 仅获取所需的目标文件进行链接,以避免由于 archive\xe2\x80\xaf 中不需要的符号而导致未定义符号错误?
\n我安装了libjpeg-dev,所有文件都在include文件夹中
/usr/include/jerror.h
/usr/include/jmorecfg.h
/usr/include/jpegint.h
/usr/include/jpeglib.h
/usr/include/turbojpeg.h
/usr/include/x86_64-linux-gnu
/usr/include/x86_64-linux-gnu/jconfig.h
Run Code Online (Sandbox Code Playgroud)
当我尝试这个简单的代码来解压缩jpeg图像时,我得到了标题中的错误.
这是代码:
#include <stdlib.h>
#include <stdio.h>
#include <jpeglib.h>
int main(void){
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 libpq 编译 C++ 应用程序。在我的 Debian 上,使用以下命令可以正常编译:
g++ -I /usr/include/postgresql/ -L /usr/lib/postgresql/9.3/lib/ -lpq -o test test.cpp
Run Code Online (Sandbox Code Playgroud)
在我的 Ubuntu 上,我收到以下错误:
undefined reference to 'PQfinish'
Run Code Online (Sandbox Code Playgroud)
我已经包含了 postgresql 标头和库的链接并使用了 -lpq。我缺少什么?
我正在尝试使用 Poco 库发送电子邮件。平台是OS X,Yosemite 10.10.2我使用的是Qt 5.3 32 位。我按照这里的官方说明进行操作,由于我使用的是 32 位 Qt,并且希望库静态链接,所以我使用
./configure --omit=Data/ODBC,Data/MySQL --config=Darwin32
(我不需要MySQL/ODBC模块)。它安装/usr/local正确,随后我链接了必要的动态库(PocoNet以及PocoFoundation其他 10 个库),并尝试了以下代码,我在此处找到了它。我想做的是从我的帐户本身向我的 Gmail 帐户发送一封电子邮件:
#include "MailSender.hpp"
#include <Poco/Net/MailMessage.h>
#include <Poco/Net/MailRecipient.h>
#include <Poco/Net/SMTPClientSession.h>
#include <Poco/Net/NetException.h>
#include <Poco/Net/SecureSMTPClientSession.h>
#include <Poco/Net/InvalidCertificateHandler.h>
#include <Poco/Net/AcceptCertificateHandler.h>
#include <Poco/Net/SSLManager.h>
#include <Poco/Net/SecureStreamSocket.h>
#include <Poco/Net/MailRecipient.h>
#include <iostream>
#include <QDebug>
using Poco::Net::InvalidCertificateHandler;
using Poco::Net::AcceptCertificateHandler;
using Poco::Net::Context;
using Poco::Net::SSLManager;
using Poco::Net::SecureStreamSocket;
using Poco::Net::SocketAddress;
using Poco::Net::SecureSMTPClientSession;
using …Run Code Online (Sandbox Code Playgroud) 我的可执行文件与许多静态库链接,在Linux上通常有50至100个存档。有时,这些档案中存在依赖性周期。这些库在链接命令行上出现的顺序很重要,请参见此处。尝试手动订购许多库至少要耗费大量时间,尤其是在存在循环的情况下。
问题:是否有实用程序或技术可以分析代码库并产生正确的链接命令行顺序?
我有以下Makefile:
CC=g++
top_srcdir=$(SRC_DIR)/cpp/src/
INCLUDES:= -I $(top_srcdir) -I $(top_srcdir)command_classes -I $(top_srcdir)platform -I $(top_srcdir)value_classes
LIBS:= -lopenzwave -lpthread -ludev
LDFLAGS += -L$(SRC_DIR) -Wl,-R$(SRC_DIR) '-Wl,-R$$ORIGIN'
all: ozw
ozw: Main.cpp
$(CC) $(INCLUDES) -c Main.cpp -o ozw-power-on-off.o
$(CC) $(LIBS) $(LDFLAGS) ozw-power-on-off.o -o ozw-power-on-off.out
clean:
rm -rf *.o *.out
Run Code Online (Sandbox Code Playgroud)
我用以下命令执行它:
make ARCH=$TARGET_ARCH \
CROSS_COMPILE=$TARGET_PREFIX \
SRC_DIR=$ROOT/$PKG_BUILD
Run Code Online (Sandbox Code Playgroud)
但它忽视ARCH和CROSS_COMPILE重视.我试图取代$(CC)与$(MAKE)和补充-$(MAKEFLAGS),但它说Nothing to be done for 'Main.cpp'.
如何修复它并添加交叉编译支持?