当我这样做时ls -l,/usr/lib我会看到很多带有"sameName.so.*.*"扩展名的库.
一个例子将有助于理解.
很多时候,我在互联网上找到了有用的代码示例.大约一半的时间他们没有指定要包含的文件,甚至没有指定要在命令行中包含-l的库.你通常如何找到它?
编辑说明:以下问题已解决.可以跳过这篇文章的其余部分.
现在,我在尝试编译时遇到了大量错误:
53: string Gunzip::gunzip(string& compressed)
54: {
55: namespace io = boost::iostreams;
56:
57: io::filtering_istream gunzip;
58: gunzip.push(io::gzip_decompressor());
59: std::istringstream in_stream = std::istringstream(compressed);
60: gunzip.push(in_stream);
61:
62: stringstream strstream;
63: io::copy(gunzip, strstream);
64: return strstream.str();
65: }
Run Code Online (Sandbox Code Playgroud)
在互联网上度过一天后,我正在尝试:
option: 3 -L/usr/include/boost
and:
8: #include <string>
9: #include <iostream>
10: #include <sstream>
15: #include <boost/iostreams/copy.hpp>
16: #include <boost/iostreams/device/array.hpp>
17: #include <boost/iostreams/device/back_inserter.hpp>
18: #include <boost/iostreams/filter/gzip.hpp>
19: #include <boost/iostreams/filter/test.hpp>
20: #include <boost/iostreams/filtering_stream.hpp>
Run Code Online (Sandbox Code Playgroud)
我遇到的错误是:
from /usr/include/c++/4.5/string:45,
from Gunzip.cpp:8:
/usr/include/c++/4.5/bits/ios_base.h: In copy constructor …Run Code Online (Sandbox Code Playgroud) 有时在我的 C++ 项目中使用纯 C 库,我会看到奇怪的(在我看来)函数声明。
例如:libldap 的ldap_search_ext():https ://linux.die.net/man/3/ldap_search_ext_s
int ldap_search_ext(
LDAP *ld,
char *base,
int scope,
char *filter,
char *attrs[], // this one!
int attrsonly,
LDAPControl **serverctrls,
LDAPControl **clientctrls,
struct timeval *timeout,
int sizelimit,
int *msgidp );
Run Code Online (Sandbox Code Playgroud)
为什么 attrs[] 不能是 a const char *?
像这样的声明不想改变指针的内容并产生很多问题:
// pure C
void func(char * data[])
{
...
}
func({"blabla"}); // won't work (corrected: yes, this is wrong syntax, but it's true for structs of pointers)
const char *d[] = …Run Code Online (Sandbox Code Playgroud) 我在Linux 64位上使用CMake时遇到问题.我在C中有一个必须链接到库(xr_arp.a)的示例,该库对另一个库(libcrypto.a)具有链接依赖性.我为构建示例代码所做的以下makefile是成功链接的:
CFLAGS = -I../Common -I../xr -I../../../openssl/include
LIBS = ../xr/xr_arp.a ../../../openssl/lib/libcrypto.a
TARGET = sample
OBJFILES = sample.o
all: $(TARGET)
$(TARGET): Makefile $(OBJFILES)
$(CC) -o $@ $(OBJFILES) $(LIBS)
clean:
rm -rf *.o $(TARGET)
.SUFFIXES: .c .o
.c.o:
$(CC) -Wall $(CFLAGS) -c $<
Run Code Online (Sandbox Code Playgroud)
但是,我想将此makefile转换为使用CMake.当我使用下面的CMakeLists.txt文件时,我得到xr_arp.c对`SHA1'的未定义引用,因为它似乎无法将xr_arp.a链接到libcrypto.a:
cmake_minimum_required(VERSION 2.8)
project (SAMPLE C)
set(CMAKE_C_FLAGS "-Wall")
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../Common
${CMAKE_CURRENT_SOURCE_DIR}/../xr
)
add_executable(
sample
sample.c
)
target_link_libraries(
sample
${CMAKE_CURRENT_SOURCE_DIR}/../../../openssl/lib/libcrypto.a
${CMAKE_CURRENT_SOURCE_DIR}/../xr/xr_arp.a
)
Run Code Online (Sandbox Code Playgroud)
有人能指出我这两个文件有什么区别吗?为什么它使用makefile而不是CMake?有没有我可以用来强制xr_arp.a和libcrypto.a之间链接的程序?请注意,这两个库都是第三方,不是我的.
假设我在运行不同Linux发行版的2台计算机上编写代码.
如何让qmake区分这两个发行版并为这两个发行版分配特定的LIBS.
例如;
unix: {
ubuntu*: {
LIBS += -lcxcore -lhighgui -lm
}
gentoo*: {
LIBS += -lopencv_imgproc -lopencv_highgui -lm
}
}
Run Code Online (Sandbox Code Playgroud) 我试图在Eclipse v3.7.2中将loopj .jar库添加到我的项目中
首先,我将.jar添加到"lib"目录中,右键单击它并选择"添加到构建路径".它编译得很好,但在执行时我得到一个错误"找不到类'com.loopj.android.http.AsyncHttpClient'.
所以我从构建路径中删除.jar,并将其移动到"libs"目录中.
当它在"libs"目录中时,不需要添加构建路径,这次它编译得很好并且执行也很好.
那么"lib"目录和"添加到构建路径"与"libs"目录之间的微妙区别是什么?
编辑:我知道可能重复,但答案不直接适用。我正在使用 ProcessBuilder 而不是 Runtime.getRuntime().exec:
public int execProcess(List<String> cmds, ShellUtils.ShellCallback sc) {
StringBuilder cmdlog = new StringBuilder();
for (String cmd : cmds) {
cmdlog.append(' ');
}
Utils.logger("v", cmdlog.toString(), DEBUG_TAG);
ProcessBuilder pb = new ProcessBuilder();
pb.directory(mBinFileDir);
pb.command(cmds);
Process process = null;
int exitVal = 1; // Default error
try {
process = pb.start();
StreamGobbler errorGobbler = new
StreamGobbler(process.getErrorStream(), "ERROR", sc);
StreamGobbler outputGobbler = new
StreamGobbler(process.getInputStream(), "OUTPUT", sc);
errorGobbler.start();
outputGobbler.start();
exitVal = process.waitFor();
sc.processComplete(exitVal);
} catch (Exception e) {
Log.e(DEBUG_TAG, "Error executing ffmpeg …Run Code Online (Sandbox Code Playgroud) 在我的 Qt 程序中,我必须将字符串转换为哈希值。我想在 Debian 上使用 OpenSSL。我的代码的简短介绍:
#include <openssl/sha.h>
...
unsigned char data[] = "data to hash";
unsigned char hash[SHA512_DIGEST_LENGTH];
SHA512(data, sizeof(data) - 1, hash);
Run Code Online (Sandbox Code Playgroud)
我已经安装了 openssl 和 libssl-dev。我还更改了我的 .pro 文档,如下所示:
TEMPLATE = app
QT = core gui
HEADERS += window.h
PKGCONFIG += openssl //found in another solution, but it does not work
LIBS += -L/usr/share/doc libssl-dev
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += main.cpp window.cpp
Run Code Online (Sandbox Code Playgroud)
在 LIBS 中,我尝试了所有可能的位置sudo dpkg -L libssl-dev。有人知道我缺少什么吗?它无法编译,我确信就是这样。
谢谢。
这是链接时的错误:
/usr/lib/x86_64-linux-gnu/qt4/bin/qmake -o Makefile App.pro
g++ …Run Code Online (Sandbox Code Playgroud) 我有 3 个文件夹的项目(我正在使用 gulp),我不需要编译。所以,我需要一个任务,这需要3个文件夹"src/fonts","src/libs"并"src/docs"作为gulp.src(),只是移动它们在dest/文件夹中。我不需要对它们做任何事情,只需在构建后移动它们即可。
我目前的尝试:
gulp.task('others', function () {
return gulp.src(['src/libs/**'], ['src/fonts/**'], ['src/docs/**'])
.pipe(gulp.dest('dist/'))
});
Run Code Online (Sandbox Code Playgroud)
使用此代码,任务仅移动内部文件和文件夹(需要包装),并且仅将“src/libs”作为 gulp.src()
我是 Linux 中 C 语言编程的新手。我喜欢用 GTKlibs 制作 GUI。唯一的问题是我无法 - 而且不仅是 gtk - 无法正确安装这些软件包。我在包含库时遇到问题,就像#include<gtk/gtk.h>我已经使用sudo apt-get install gtklib-3-dev.
在编译时,它每次都会说文件丢失等等。我已阅读将 dpkg 配置和 cflags 放入编译器的选项,但这也不起作用。linux 如何管理包含文件夹以及为什么像 gtk 这样的库有一个上层文件夹,上面有 gtk3 等版本。这就是导致文件丢失的问题。
我想将一些环境变量加载到我的库中的函数中,然后能够将其重新导出到几个不同的 Nextjs 应用程序。IE
之内libs/api
export const getDatabaseConnection = () => {
const host = process.env.DB_HOST
const username = process.env.DB_USERNAME
...
return newDatabaseConnection
}
Run Code Online (Sandbox Code Playgroud)
在 apps/myNextJSApp 内:
import { getDatabaseConnection } from '@myProject/api'
...
const databaseConnection = getDatabaseConnection()
...
Run Code Online (Sandbox Code Playgroud)
当我运行时,nx run myNextJSApp:serve它无法从根目录中的 .env 中提取环境变量,但是如果我运行它,nx run api:test它就完全满意了。我想我可以单独从每个应用程序中提取环境变量,然后将它们作为参数传递到我的库函数中,但这似乎有点乏味,我希望有一个全面的解决方案,我可以使用以下命令构建我的库模块环境变量,并将它们导出到我的 NextJS 应用程序。