AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题

问题[gcc](unix)

Martin Hope
Vinod
Asked: 2025-02-13 09:51:49 +0800 CST

cc/gcc -R 标志到链接器

  • 5

参考: 弱符号

在链接中提到了以下链接器选项:

cc  main.o -L`pwd` -Wl,-R`pwd` -lpowerslow -o main2

除 之外,所有上述标志的用途均已在 GCC 手册中记录-R。

这个标志指示链接器什么?

短暂性脑缺血发作

维诺德

gcc
  • 2 个回答
  • 25 Views
Martin Hope
user3384486
Asked: 2024-08-08 05:34:43 +0800 CST

dlsym 从 LD_PRELOAD 插入器运行时,未找到主程序中的任何符号

  • 5
/* dlsym-main.c */

#include <stdio.h>

void doSomething(char const *msg)
{
    fprintf(stderr, "Main program is doing %s\n", msg);
}

void (*fnptr)(char const *) = doSomething;

int main() {

    fnptr("some printing");
    return 0;
}
/* dlsym-lib.c */

#define _GNU_SOURCE  1
#include <stdio.h>
#include <dlfcn.h>

void myLibraryFunc(char const *msg)
{
    fprintf(stdout, "My library is doing %s\n", msg);
}

void hook(void)
{
    // Load the current executable as a shared object
    void* handle = dlopen(NULL, RTLD_LAZY);
    if (!handle) {
        fprintf(stderr, "Error: %s\n", dlerror());
        return;
    }

   typedef void (*fnT)(char const *);

    // Dynamically resolve the global non-static variable
    fnT* fnPtr = (fnT*) dlsym(handle, "fnptr");
    if (!fnPtr)
    {
        fprintf(stderr, "Error locating fnptr: %s\n", dlerror());
        dlclose(handle);
        return;
    }
    *fnPtr = myLibraryFunc;

    // Close the handle
    dlclose(handle);
}

__attribute__((constructor))
void setup() { hook(); }
## Makefile

linky: dlsym-main.c
    gcc -o linky dlsym-main.c
libi.so: dlsym-lib.c
    gcc -shared -fPIC -o libi.so dlsym-lib.c -ldl

run: linky libi.so
    LD_PRELOAD=$$PWD/libi.so ./linky

输出make run:

Error locating fnptr: Symbol not found: fnptr
Main program is doing some printing

符号(fnptr)是一个全局数据对象:

> objdump -t linky | grep fnptr
0000000000020008 g     O .data  0000000000000008 fnptr

使用LD_DEBUG=symbols(Debian)表明它正在可执行文件中查找:

       318: symbol=fnptr;  lookup in file=./linky [0]
       318: symbol=fnptr;  lookup in file=/CDS/libi.so [0]
       318: symbol=fnptr;  lookup in file=/usr/lib/aarch64-linux-gnu/libstdc++.so.6 [0]
       318: symbol=fnptr;  lookup in file=/lib/aarch64-linux-gnu/libc.so.6 [0]
       318: symbol=fnptr;  lookup in file=/lib/aarch64-linux-gnu/libdl.so.2 [0]
       318: symbol=fnptr;  lookup in file=/lib/aarch64-linux-gnu/libm.so.6 [0]
       318: symbol=fnptr;  lookup in file=/lib/aarch64-linux-gnu/libgcc_s.so.1 [0]
       318: symbol=fnptr;  lookup in file=/lib/ld-linux-aarch64.so.1 [0]
       318: /CDS/libi.so: error: symbol lookup error: undefined symbol: fnptr (fatal)

我在 Debian、Alpine(musl libc)和其他变体(所有 GCC)上尝试过此操作,结果相同。我问过 AI 机器人如何做到这一点,它们吐出了这段代码。

相同的代码在 macOS 上运行良好

▶ make run_macOS
DYLD_INSERT_LIBRARIES=$PWD/libi.so ./linky
My library is doing some printing

我做错了什么,导致这在 GCC 上不起作用?

gcc
  • 1 个回答
  • 15 Views
Martin Hope
PhillNo
Asked: 2024-07-31 12:32:06 +0800 CST

gcc 和 g++ 现在是不同的可执行文件吗?

  • 5

根据下面链接的评论和已接受的答案,gcc 和 g++ 是相同的可执行文件。因为它们相同,所以 的值argv[0]将决定行为,无论参数是“gcc”还是“g++”。

查看已接受的答案

这里的一些评论似乎证实了这一点,但有些评论似乎暗示了单独的可执行文件

但是,我发现两者的 inode 编号(和文件大小)不同。

owner@fedora:~/code/make_test$ ls -ilh /usr/bin/gcc
1584205 -rwxr-xr-x. 3 root root 1020K May 21 17:00 /usr/bin/gcc
owner@fedora:~/code/make_test$ ls -ilh /usr/bin/g++
1584212 -rwxr-xr-x. 4 root root 1.0M May 21 17:00 /usr/bin/g++

在使用该标志编译 hello_world.cpp 程序时,我偶然观察到了以下内容-v:

gcc version 13.3.1 20240522 (Red Hat 13.3.1-1) (GCC)

我考虑过 Red Hat 用自己的习惯用法实现了自己的 gcc 的可能性,但我的 gcc 安装似乎并非来自任何非标准存储库。我使用的是 Fedora 39,没想到我的操作系统中会有 Red Hat 内容(尽管我不明白为什么 RH 内容不能在某个时候合并到上游发行版中)。

owner@fedora:~/code/make_test$ dnf repolist
repo id                                                                                                       repo name
fedora                                                                                                        Fedora 39 - x86_64
fedora-cisco-openh264                                                                                         Fedora 39 openh264 (From Cisco) - x86_64
opera                                                                                                         Opera packages
rpmfusion-free                                                                                                RPM Fusion for Fedora 39 - Free
rpmfusion-free-updates                                                                                        RPM Fusion for Fedora 39 - Free - Updates
rpmfusion-nonfree                                                                                             RPM Fusion for Fedora 39 - Nonfree
rpmfusion-nonfree-updates                                                                                     RPM Fusion for Fedora 39 - Nonfree - Updates
updates                                                                                                       Fedora 39 - x86_64 - Updates

owner@fedora:~/code/make_test$ dnf whatprovides gcc
Last metadata expiration check: 0:02:01 ago on Tue 30 Jul 2024 08:16:27 PM MST.
gcc-13.2.1-3.fc39.x86_64 : Various compilers (C, C++, Objective-C, ...)
Repo        : fedora
Matched from:
Provide    : gcc = 13.2.1-3.fc39

gcc-13.3.1-1.fc39.x86_64 : Various compilers (C, C++, Objective-C, ...)
Repo        : @System
Matched from:
Provide    : gcc = 13.3.1-1.fc39

gcc-13.3.1-1.fc39.x86_64 : Various compilers (C, C++, Objective-C, ...)
Repo        : updates
Matched from:
Provide    : gcc = 13.3.1-1.fc39

因此,我相信我拥有“官方” gcc,但我不明白为什么 gcc 和 g++ 不是同一个文件。gcc 和 g++ 现在是不同的可执行文件吗?它们一直都是不同的吗?如果不是,它们是什么时候分开的?还是我只是被误导了,认为它们曾经是相同的?

gcc
  • 1 个回答
  • 49 Views
Martin Hope
Jagemann
Asked: 2023-10-17 16:35:01 +0800 CST

在运行 VMware 之前,必须编译几个模块(vmmon 和 vmnet)

  • 6

我刚刚重新启动 Pop!_OS,当尝试打开 vmware 时,它​​说我必须编译几个模块。然后它继续尝试编译 vmmon 和 vmnet,但失败了。并给我一个错误日志文件。

我尝试使用 更改 gcc 版本 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/x86_64-linux-gnu-gcc-12 100,这似乎没有更改错误文件。

我也尝试过跑步,sudo vmware-modconfig --console --install-all但这也失败了。

错误日志文件:

2023-10-17T08:12:11.525Z In(05) host-26414 Log for VMware Workstation pid=26414 version=17.0.2 build=build-21581411 option=Release
2023-10-17T08:12:11.525Z In(05) host-26414 The host is x86_64.
2023-10-17T08:12:11.525Z In(05) host-26414 Host codepage=UTF-8 encoding=UTF-8
2023-10-17T08:12:11.525Z In(05) host-26414 Host is Linux 6.5.4-76060504-generic Pop!_OS 22.04 LTS Pop!_OS 22.04
2023-10-17T08:12:11.525Z In(05) host-26414 Host offset from UTC is +02:00.
2023-10-17T08:12:11.525Z In(05) host-26414 DictionaryLoad: Cannot open file "/usr/lib/vmware/settings": No such file or directory.
2023-10-17T08:12:11.525Z In(05) host-26414 [msg.dictionary.load.openFailed] Cannot open file "/usr/lib/vmware/settings": No such file or directory.
2023-10-17T08:12:11.525Z In(05) host-26414 PREF Optional preferences file not found at /usr/lib/vmware/settings. Using default values.
2023-10-17T08:12:11.525Z In(05) host-26414 DictionaryLoad: Cannot open file "/home/grimley/.vmware/config": No such file or directory.
2023-10-17T08:12:11.525Z In(05) host-26414 [msg.dictionary.load.openFailed] Cannot open file "/home/grimley/.vmware/config": No such file or directory.
2023-10-17T08:12:11.525Z In(05) host-26414 PREF Optional preferences file not found at /home/grimley/.vmware/config. Using default values.
2023-10-17T08:12:11.606Z Wa(03) host-26414 Logging to /tmp/vmware-grimley/vmware-26414.log
2023-10-17T08:12:11.614Z In(05) host-26414 Obtaining info using the running kernel.
2023-10-17T08:12:11.614Z In(05) host-26414 Created new pathsHash.
2023-10-17T08:12:11.614Z In(05) host-26414 Setting header path for 6.5.4-76060504-generic to "/lib/modules/6.5.4-76060504-generic/build/include".
2023-10-17T08:12:11.614Z In(05) host-26414 Validating path "/lib/modules/6.5.4-76060504-generic/build/include" for kernel release "6.5.4-76060504-generic".
2023-10-17T08:12:11.614Z In(05) host-26414 Failed to find /lib/modules/6.5.4-76060504-generic/build/include/linux/version.h
2023-10-17T08:12:11.614Z In(05) host-26414 /lib/modules/6.5.4-76060504-generic/build/include/linux/version.h not found, looking for generated/uapi/linux/version.h instead.
2023-10-17T08:12:11.614Z In(05) host-26414 using /usr/bin/gcc-12 for preprocess check
2023-10-17T08:12:11.619Z In(05) host-26414 Preprocessed UTS_RELEASE, got value "6.5.4-76060504-generic".
2023-10-17T08:12:11.619Z In(05) host-26414 The header path "/lib/modules/6.5.4-76060504-generic/build/include" for the kernel "6.5.4-76060504-generic" is valid.  Whoohoo!
2023-10-17T08:12:11.885Z In(05) host-26414 found symbol version file /lib/modules/6.5.4-76060504-generic/build/Module.symvers
2023-10-17T08:12:11.885Z In(05) host-26414 Reading symbol versions from /lib/modules/6.5.4-76060504-generic/build/Module.symvers.
2023-10-17T08:12:11.904Z In(05) host-26414 Read 28017 symbol versions
2023-10-17T08:12:11.904Z In(05) host-26414 Reading in info for the vmmon module.
2023-10-17T08:12:11.904Z In(05) host-26414 Reading in info for the vmnet module.
2023-10-17T08:12:11.904Z In(05) host-26414 Invoking modinfo on "vmmon".
2023-10-17T08:12:11.907Z In(05) host-26414 "/sbin/modinfo" exited with status 256.
2023-10-17T08:12:11.907Z In(05) host-26414 Invoking modinfo on "vmnet".
2023-10-17T08:12:11.909Z In(05) host-26414 "/sbin/modinfo" exited with status 256.
2023-10-17T08:12:11.922Z In(05) host-26414 to be installed: vmmon status: 0
2023-10-17T08:12:11.922Z In(05) host-26414 to be installed: vmnet status: 0
2023-10-17T08:12:11.934Z In(05) host-26414 Obtaining info using the running kernel.
2023-10-17T08:12:11.934Z In(05) host-26414 Setting header path for 6.5.4-76060504-generic to "/lib/modules/6.5.4-76060504-generic/build/include".
2023-10-17T08:12:11.934Z In(05) host-26414 Validating path "/lib/modules/6.5.4-76060504-generic/build/include" for kernel release "6.5.4-76060504-generic".
2023-10-17T08:12:11.934Z In(05) host-26414 Failed to find /lib/modules/6.5.4-76060504-generic/build/include/linux/version.h
2023-10-17T08:12:11.934Z In(05) host-26414 /lib/modules/6.5.4-76060504-generic/build/include/linux/version.h not found, looking for generated/uapi/linux/version.h instead.
2023-10-17T08:12:11.934Z In(05) host-26414 using /usr/bin/gcc-12 for preprocess check
2023-10-17T08:12:11.940Z In(05) host-26414 Preprocessed UTS_RELEASE, got value "6.5.4-76060504-generic".
2023-10-17T08:12:11.940Z In(05) host-26414 The header path "/lib/modules/6.5.4-76060504-generic/build/include" for the kernel "6.5.4-76060504-generic" is valid.  Whoohoo!
2023-10-17T08:12:12.203Z In(05) host-26414 found symbol version file /lib/modules/6.5.4-76060504-generic/build/Module.symvers
2023-10-17T08:12:12.203Z In(05) host-26414 Reading symbol versions from /lib/modules/6.5.4-76060504-generic/build/Module.symvers.
2023-10-17T08:12:12.221Z In(05) host-26414 Read 28017 symbol versions
2023-10-17T08:12:12.222Z In(05) host-26414 Kernel header path retrieved from FileEntry: /lib/modules/6.5.4-76060504-generic/build/include
2023-10-17T08:12:12.222Z In(05) host-26414 Update kernel header path to /lib/modules/6.5.4-76060504-generic/build/include
2023-10-17T08:12:12.222Z In(05) host-26414 Validating path "/lib/modules/6.5.4-76060504-generic/build/include" for kernel release "6.5.4-76060504-generic".
2023-10-17T08:12:12.223Z In(05) host-26414 Failed to find /lib/modules/6.5.4-76060504-generic/build/include/linux/version.h
2023-10-17T08:12:12.223Z In(05) host-26414 /lib/modules/6.5.4-76060504-generic/build/include/linux/version.h not found, looking for generated/uapi/linux/version.h instead.
2023-10-17T08:12:12.223Z In(05) host-26414 using /usr/bin/gcc-12 for preprocess check
2023-10-17T08:12:12.228Z In(05) host-26414 Preprocessed UTS_RELEASE, got value "6.5.4-76060504-generic".
2023-10-17T08:12:12.228Z In(05) host-26414 The header path "/lib/modules/6.5.4-76060504-generic/build/include" for the kernel "6.5.4-76060504-generic" is valid.  Whoohoo!
2023-10-17T08:12:12.229Z In(05) host-26414 Attempting to use a compiler at location "/usr/bin/gcc-12".
2023-10-17T08:12:12.231Z In(05) host-26414 Got gcc version "12".
2023-10-17T08:12:12.231Z In(05) host-26414 The GCC version matches the kernel GCC minor version like a glove.
2023-10-17T08:12:12.232Z In(05) host-26414 Got gcc version "12".
2023-10-17T08:12:12.232Z In(05) host-26414 The GCC version matches the kernel GCC minor version like a glove.
2023-10-17T08:12:12.233Z In(05) host-26414 Trying to find a suitable PBM set for kernel "6.5.4-76060504-generic".
2023-10-17T08:12:12.233Z In(05) host-26414 No matching PBM set was found for kernel "6.5.4-76060504-generic".
2023-10-17T08:12:12.233Z In(05) host-26414 The GCC version matches the kernel GCC minor version like a glove.
2023-10-17T08:12:12.233Z In(05) host-26414 Validating path "/lib/modules/6.5.4-76060504-generic/build/include" for kernel release "6.5.4-76060504-generic".
2023-10-17T08:12:12.233Z In(05) host-26414 Failed to find /lib/modules/6.5.4-76060504-generic/build/include/linux/version.h
2023-10-17T08:12:12.233Z In(05) host-26414 /lib/modules/6.5.4-76060504-generic/build/include/linux/version.h not found, looking for generated/uapi/linux/version.h instead.
2023-10-17T08:12:12.233Z In(05) host-26414 using /usr/bin/gcc-12 for preprocess check
2023-10-17T08:12:12.239Z In(05) host-26414 Preprocessed UTS_RELEASE, got value "6.5.4-76060504-generic".
2023-10-17T08:12:12.239Z In(05) host-26414 The header path "/lib/modules/6.5.4-76060504-generic/build/include" for the kernel "6.5.4-76060504-generic" is valid.  Whoohoo!
2023-10-17T08:12:14.992Z In(05) host-26414 The GCC version matches the kernel GCC minor version like a glove.
2023-10-17T08:12:14.992Z In(05) host-26414 Validating path "/lib/modules/6.5.4-76060504-generic/build/include" for kernel release "6.5.4-76060504-generic".
2023-10-17T08:12:14.992Z In(05) host-26414 Failed to find /lib/modules/6.5.4-76060504-generic/build/include/linux/version.h
2023-10-17T08:12:14.992Z In(05) host-26414 /lib/modules/6.5.4-76060504-generic/build/include/linux/version.h not found, looking for generated/uapi/linux/version.h instead.
2023-10-17T08:12:14.992Z In(05) host-26414 using /usr/bin/gcc-12 for preprocess check
2023-10-17T08:12:15.006Z In(05) host-26414 Preprocessed UTS_RELEASE, got value "6.5.4-76060504-generic".
2023-10-17T08:12:15.006Z In(05) host-26414 The header path "/lib/modules/6.5.4-76060504-generic/build/include" for the kernel "6.5.4-76060504-generic" is valid.  Whoohoo!
2023-10-17T08:12:15.006Z In(05) host-26414 Using temp dir "/tmp".
2023-10-17T08:12:23.261Z In(05) host-26414 Stopping VMware services:
2023-10-17T08:12:23.261Z In(05) host-26414    VMware Authentication Daemon[71G done
2023-10-17T08:12:23.261Z In(05) host-26414    Virtual machine monitor[71G done
2023-10-17T08:12:23.261Z In(05) host-26414 make: Entering directory '/tmp/modconfig-Q8NuOz/vmmon-only'
2023-10-17T08:12:23.261Z In(05) host-26414 /usr/bin/make -C /lib/modules/6.5.4-76060504-generic/build/include/.. M=$PWD SRCROOT=$PWD/. \
2023-10-17T08:12:23.261Z In(05) host-26414   MODULEBUILDDIR= modules
2023-10-17T08:12:23.261Z In(05) host-26414 make[1]: Entering directory '/usr/src/linux-headers-6.5.4-76060504-generic'
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/linux/driver.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/linux/driverLog.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/linux/hostif.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/common/apic.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/common/comport.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/common/cpuid.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/common/crosspage.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/common/memtrack.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/common/moduleloop.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/common/phystrack.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/common/sharedAreaVmmon.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/common/statVarsVmmon.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/common/task.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/common/vmx86.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/bootstrap/bootstrap.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/bootstrap/monLoader.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/bootstrap/monLoaderVmmon.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmmon-only/bootstrap/vmmblob.o
2023-10-17T08:12:23.261Z In(05) host-26414   LD [M]  /tmp/modconfig-Q8NuOz/vmmon-only/vmmon.o
2023-10-17T08:12:23.261Z In(05) host-26414   MODPOST /tmp/modconfig-Q8NuOz/vmmon-only/Module.symvers
2023-10-17T08:12:23.261Z In(05) host-26414 make[1]: Leaving directory '/usr/src/linux-headers-6.5.4-76060504-generic'
2023-10-17T08:12:23.261Z In(05) host-26414 make: Leaving directory '/tmp/modconfig-Q8NuOz/vmmon-only'
2023-10-17T08:12:23.261Z In(05) host-26414 make: Entering directory '/tmp/modconfig-Q8NuOz/vmnet-only'
2023-10-17T08:12:23.261Z In(05) host-26414 /usr/bin/make -C /lib/modules/6.5.4-76060504-generic/build/include/.. M=$PWD SRCROOT=$PWD/. \
2023-10-17T08:12:23.261Z In(05) host-26414   MODULEBUILDDIR= modules
2023-10-17T08:12:23.261Z In(05) host-26414 make[1]: Entering directory '/usr/src/linux-headers-6.5.4-76060504-generic'
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmnet-only/driver.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmnet-only/hub.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmnet-only/userif.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmnet-only/netif.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmnet-only/bridge.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmnet-only/procfs.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmnet-only/smac_compat.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmnet-only/smac.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmnet-only/vnetEvent.o
2023-10-17T08:12:23.261Z In(05) host-26414   CC [M]  /tmp/modconfig-Q8NuOz/vmnet-only/vnetUserListener.o
2023-10-17T08:12:23.261Z In(05) host-26414 make[1]: Leaving directory '/usr/src/linux-headers-6.5.4-76060504-generic'
2023-10-17T08:12:23.261Z In(05) host-26414 make: Leaving directory '/tmp/modconfig-Q8NuOz/vmnet-only'
2023-10-17T08:12:23.261Z In(05) host-26414 [AppLoader] GLib does not have GSettings support.
2023-10-17T08:12:23.261Z In(05) host-26414 Using kernel build system.
2023-10-17T08:12:23.261Z In(05) host-26414 warning: the compiler differs from the one used to build the kernel
2023-10-17T08:12:23.261Z In(05) host-26414   The kernel was built by: x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
2023-10-17T08:12:23.261Z In(05) host-26414   You are using:           gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
2023-10-17T08:12:23.261Z In(05) host-26414 /tmp/modconfig-Q8NuOz/vmmon-only/common/crosspage.o: warning: objtool: CrossPage_CodePage+0x207: 'naked' return found in RETHUNK build
2023-10-17T08:12:23.261Z In(05) host-26414 /tmp/modconfig-Q8NuOz/vmmon-only/common/phystrack.o: warning: objtool: PhysTrack_Add() falls through to next function PhysTrack_Remove()
2023-10-17T08:12:23.261Z In(05) host-26414 /tmp/modconfig-Q8NuOz/vmmon-only/common/phystrack.o: warning: objtool: PhysTrack_Remove() falls through to next function PhysTrack_Test()
2023-10-17T08:12:23.261Z In(05) host-26414 /tmp/modconfig-Q8NuOz/vmmon-only/bootstrap/monLoader.c: In function ‘MonLoader_Process’:
2023-10-17T08:12:23.261Z In(05) host-26414 /tmp/modconfig-Q8NuOz/vmmon-only/bootstrap/monLoader.c:794:24: warning: the comparison will always evaluate as ‘false’ for the address of ‘entries’ will never be NULL [-Waddress]
2023-10-17T08:12:23.261Z In(05) host-26414   794 |    if (header->entries == 0 || header->count == 0) {
2023-10-17T08:12:23.261Z In(05) host-26414       |                        ^~
2023-10-17T08:12:23.261Z In(05) host-26414 In file included from /tmp/modconfig-Q8NuOz/vmmon-only/bootstrap/monLoader.c:57:
2023-10-17T08:12:23.261Z In(05) host-26414 /tmp/modconfig-Q8NuOz/vmmon-only/./include/monLoader.h:239:19: note: ‘entries’ declared here
2023-10-17T08:12:23.261Z In(05) host-26414   239 |    MonLoaderEntry entries[];
2023-10-17T08:12:23.261Z In(05) host-26414       |                   ^~~~~~~
2023-10-17T08:12:23.261Z In(05) host-26414 In file included from /tmp/modconfig-Q8NuOz/vmmon-only/./include/cpu_types.h:29,
2023-10-17T08:12:23.261Z In(05) host-26414                  from /tmp/modconfig-Q8NuOz/vmmon-only/./include/modulecall.h:33,
2023-10-17T08:12:23.261Z In(05) host-26414                  from /tmp/modconfig-Q8NuOz/vmmon-only/common/moduleloop.c:33:
2023-10-17T08:12:23.261Z In(05) host-26414 /tmp/modconfig-Q8NuOz/vmmon-only/./include/vm_basic_defs.h:779: warning: "DO_ONCE" redefined
2023-10-17T08:12:23.261Z In(05) host-26414   779 | #define DO_ONCE(code)                                                   \
2023-10-17T08:12:23.261Z In(05) host-26414       | 
2023-10-17T08:12:23.261Z In(05) host-26414 In file included from ./include/linux/prandom.h:12,
2023-10-17T08:12:23.261Z In(05) host-26414                  from ./include/linux/random.h:153,
2023-10-17T08:12:23.261Z In(05) host-26414                  from ./include/linux/nodemask.h:97,
2023-10-17T08:12:23.261Z In(05) host-26414                  from ./include/linux/sched.h:23,
2023-10-17T08:12:23.261Z In(05) host-26414                  from /tmp/modconfig-Q8NuOz/vmmon-only/common/moduleloop.c:31:
2023-10-17T08:12:23.261Z In(05) host-26414 ./include/linux/once.h:46: note: this is the location of the previous definition
2023-10-17T08:12:23.261Z In(05) host-26414    46 | #define DO_ONCE(func, ...)                                                   \
2023-10-17T08:12:23.261Z In(05) host-26414       | 
2023-10-17T08:12:23.261Z In(05) host-26414 In file included from /tmp/modconfig-Q8NuOz/vmmon-only/./include/cpu_types.h:29,
2023-10-17T08:12:23.261Z In(05) host-26414                  from /tmp/modconfig-Q8NuOz/vmmon-only/./include/modulecall.h:33,
2023-10-17T08:12:23.261Z In(05) host-26414                  from /tmp/modconfig-Q8NuOz/vmmon-only/common/vmx86.h:33,
2023-10-17T08:12:23.261Z In(05) host-26414                  from /tmp/modconfig-Q8NuOz/vmmon-only/common/vmx86.c:38:
2023-10-17T08:12:23.261Z In(05) host-26414 /tmp/modconfig-Q8NuOz/vmmon-only/./include/vm_basic_defs.h:779: warning: "DO_ONCE" redefined
2023-10-17T08:12:23.261Z In(05) host-26414   779 | #define DO_ONCE(code)                                                   \
2023-10-17T08:12:23.261Z In(05) host-26414       | 
2023-10-17T08:12:23.261Z In(05) host-26414 In file included from ./include/linux/prandom.h:12,
2023-10-17T08:12:23.261Z In(05) host-26414                  from ./include/linux/random.h:153,
2023-10-17T08:12:23.261Z In(05) host-26414                  from ./include/linux/nodemask.h:97,
2023-10-17T08:12:23.261Z In(05) host-26414                  from ./include/linux/sched.h:23,
2023-10-17T08:12:23.261Z In(05) host-26414                  from /tmp/modconfig-Q8NuOz/vmmon-only/common/vmx86.c:31:
2023-10-17T08:12:23.261Z In(05) host-26414 ./include/linux/once.h:46: note: this is the location of the previous definition
2023-10-17T08:12:23.261Z In(05) host-26414    46 | #define DO_ONCE(func, ...)                                                   \
2023-10-17T08:12:23.261Z In(05) host-26414       | 
2023-10-17T08:12:23.261Z In(05) host-26414 In file included from /tmp/modconfig-Q8NuOz/vmmon-only/./include/cpu_types.h:29,
2023-10-17T08:12:23.261Z In(05) host-26414                  from /tmp/modconfig-Q8NuOz/vmmon-only/./include/modulecall.h:33,
2023-10-17T08:12:23.261Z In(05) host-26414                  from /tmp/modconfig-Q8NuOz/vmmon-only/linux/hostif.c:58:
2023-10-17T08:12:23.261Z In(05) host-26414 /tmp/modconfig-Q8NuOz/vmmon-only/./include/vm_basic_defs.h:779: warning: "DO_ONCE" redefined
2023-10-17T08:12:23.261Z In(05) host-26414   779 | #define DO_ONCE(code)                                                   \
2023-10-17T08:12:23.261Z In(05) host-26414       | 
2023-10-17T08:12:23.261Z In(05) host-26414 In file included from ./include/linux/prandom.h:12,
2023-10-17T08:12:23.261Z In(05) host-26414                  from ./include/linux/random.h:153,
2023-10-17T08:12:23.261Z In(05) host-26414                  from ./include/linux/nodemask.h:97,
2023-10-17T08:12:23.261Z In(05) host-26414                  from ./include/linux/sched.h:23,
2023-10-17T08:12:23.261Z In(05) host-26414                  from ./include/linux/binfmts.h:5,
2023-10-17T08:12:23.261Z In(05) host-26414                  from /tmp/modconfig-Q8NuOz/vmmon-only/linux/hostif.c:31:
2023-10-17T08:12:23.261Z In(05) host-26414 ./include/linux/once.h:46: note: this is the location of the previous definition
2023-10-17T08:12:23.261Z In(05) host-26414    46 | #define DO_ONCE(func, ...)                                                   \
2023-10-17T08:12:23.261Z In(05) host-26414       | 
2023-10-17T08:12:23.261Z In(05) host-26414 In file included from /tmp/modconfig-Q8NuOz/vmmon-only/./include/cpu_types.h:29,
2023-10-17T08:12:23.261Z In(05) host-26414                  from /tmp/modconfig-Q8NuOz/vmmon-only/./include/modulecall.h:33,
2023-10-17T08:12:23.261Z In(05) host-26414                  from /tmp/modconfig-Q8NuOz/vmmon-only/./common/vmx86.h:33,
2023-10-17T08:12:23.261Z In(05) host-26414                  from /tmp/modconfig-Q8NuOz/vmmon-only/linux/driver.h:32,
2023-10-17T08:12:23.261Z In(05) host-26414                  from /tmp/modconfig-Q8NuOz/vmmon-only/linux/driver.c:47:
2023-10-17T08:12:23.261Z In(05) host-26414 /tmp/modconfig-Q8NuOz/vmmon-only/./include/vm_basic_defs.h:779: warning: "DO_ONCE" redefined
2023-10-17T08:12:23.261Z In(05) host-26414   779 | #define DO_ONCE(code)                                                   \
2023-10-17T08:12:23.261Z In(05) host-26414       | 
2023-10-17T08:12:23.261Z In(05) host-26414 In file included from ./include/linux/prandom.h:12,
2023-10-17T08:12:23.261Z In(05) host-26414                  from ./include/linux/random.h:153,
2023-10-17T08:12:23.261Z In(05) host-26414                  from ./include/linux/nodemask.h:97,
2023-10-17T08:12:23.261Z In(05) host-26414                  from ./include/linux/list_lru.h:12,
2023-10-17T08:12:23.261Z In(05) host-26414                  from ./include/linux/fs.h:13,
2023-10-17T08:12:23.261Z In(05) host-26414                  from ./include/linux/highmem.h:5,
2023-10-17T08:12:23.261Z In(05) host-26414                  from /tmp/modconfig-Q8NuOz/vmmon-only/linux/driver.c:25:
2023-10-17T08:12:23.261Z In(05) host-26414 ./include/linux/once.h:46: note: this is the location of the previous definition
2023-10-17T08:12:23.261Z In(05) host-26414    46 | #define DO_ONCE(func, ...)                                                   \
2023-10-17T08:12:23.261Z In(05) host-26414       | 
2023-10-17T08:12:23.261Z In(05) host-26414 /tmp/modconfig-Q8NuOz/vmmon-only/common/task.o: warning: objtool: .text: unexpected end of section
2023-10-17T08:12:23.261Z In(05) host-26414 ERROR: modpost: "__pte_offset_map" [/tmp/modconfig-Q8NuOz/vmmon-only/vmmon.ko] undefined!
2023-10-17T08:12:23.261Z In(05) host-26414 make[3]: *** [scripts/Makefile.modpost:144: /tmp/modconfig-Q8NuOz/vmmon-only/Module.symvers] Error 1
2023-10-17T08:12:23.261Z In(05) host-26414 make[2]: *** [/usr/src/linux-headers-6.5.4-76060504-generic/Makefile:1992: modpost] Error 2
2023-10-17T08:12:23.261Z In(05) host-26414 make[1]: *** [Makefile:234: __sub-make] Error 2
2023-10-17T08:12:23.261Z In(05) host-26414 make: *** [Makefile:117: vmmon.ko] Error 2
2023-10-17T08:12:23.261Z In(05) host-26414 Using kernel build system.
2023-10-17T08:12:23.261Z In(05) host-26414 warning: the compiler differs from the one used to build the kernel
2023-10-17T08:12:23.261Z In(05) host-26414   The kernel was built by: x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
2023-10-17T08:12:23.261Z In(05) host-26414   You are using:           gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
2023-10-17T08:12:23.261Z In(05) host-26414 /tmp/modconfig-Q8NuOz/vmnet-only/bridge.c: In function ‘VNetBridgeSendLargePacket’:
2023-10-17T08:12:23.261Z In(05) host-26414 /tmp/modconfig-Q8NuOz/vmnet-only/bridge.c:1413:11: error: implicit declaration of function ‘skb_gso_segment’; did you mean ‘tcp_gso_segment’? [-Werror=implicit-function-declaration]
2023-10-17T08:12:23.261Z In(05) host-26414  1413 |    segs = skb_gso_segment(skb, 0);
2023-10-17T08:12:23.261Z In(05) host-26414       |           ^~~~~~~~~~~~~~~
2023-10-17T08:12:23.261Z In(05) host-26414       |           tcp_gso_segment
2023-10-17T08:12:23.261Z In(05) host-26414 /tmp/modconfig-Q8NuOz/vmnet-only/bridge.c:1413:9: warning: assignment to ‘struct sk_buff *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
2023-10-17T08:12:23.261Z In(05) host-26414  1413 |    segs = skb_gso_segment(skb, 0);
2023-10-17T08:12:23.261Z In(05) host-26414       |         ^
2023-10-17T08:12:23.261Z In(05) host-26414 /tmp/modconfig-Q8NuOz/vmnet-only/userif.o: warning: objtool: VNetCsumAndCopyToUser+0x2d: call to csum_partial_copy_nocheck() with UACCESS enabled
2023-10-17T08:12:23.261Z In(05) host-26414 cc1: some warnings being treated as errors
2023-10-17T08:12:23.261Z In(05) host-26414 make[3]: *** [scripts/Makefile.build:243: /tmp/modconfig-Q8NuOz/vmnet-only/bridge.o] Error 1
2023-10-17T08:12:23.261Z In(05) host-26414 make[3]: *** Waiting for unfinished jobs....
2023-10-17T08:12:23.261Z In(05) host-26414 make[2]: *** [/usr/src/linux-headers-6.5.4-76060504-generic/Makefile:2040: /tmp/modconfig-Q8NuOz/vmnet-only] Error 2
2023-10-17T08:12:23.261Z In(05) host-26414 make[1]: *** [Makefile:234: __sub-make] Error 2
2023-10-17T08:12:23.261Z In(05) host-26414 make: *** [Makefile:117: vmnet.ko] Error 2
2023-10-17T08:12:23.261Z In(05) host-26414 Unable to install all modules.  See log for details.
2023-10-17T08:12:23.261Z In(05) host-26414 
gcc
  • 1 个回答
  • 38 Views
Martin Hope
BMac
Asked: 2023-06-13 14:18:38 +0800 CST

“无法打开@@:没有这样的文件”使用 Linaro/Libre Computer 工具链构建 atf

  • 5

我正在尝试按照列出的说明在 Debian 11 虚拟机上在此git 存储库中重新编译 Libre Computer AML-S905X-CC 的引导加载程序。该构建在尝试构建 atf(Arm 可信固件)时抛出一些错误。这是该构建部分的输出:

username@debian11:~/libretech-builder-simple$ PATH=/home/username/libretech-builder-simple/gcc/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-elf/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games CROSS_COMPILE=aarch64-elf- make -C atf -j1 PLAT=gxl DEBUG=0 bl31
make: Entering directory '/home/username/libretech-builder-simple/atf'
  CC      bl31/bl31_context_mgmt.c
/home/username/libretech-builder-simple/gcc/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-elf/bin/aarch64-elf-gcc: 1: cannot open @@: No such file
/home/username/libretech-builder-simple/gcc/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-elf/bin/aarch64-elf-gcc: 2: Syntax error: ")" unexpected
make: *** [Makefile:1469: /home/username/libretech-builder-simple/atf/build/gxl/release/bl31/bl31_context_mgmt.o] Error 2
make: Leaving directory '/home/username/libretech-builder-simple/atf'

这些错误消息对我来说似乎很神秘。bl31/bl31_context_mgmt.c任何地方都不包含“@@”。@@ 是什么,它来自哪里?

gcc
  • 1 个回答
  • 14 Views
Martin Hope
jian
Asked: 2022-07-08 07:38:45 +0800 CST

gcc 版本 9 中 libm.a 的完整路径

  • 0

基于此:https :
//stackoverflow.com/questions/5925678/location-of-c-standard-library gcc --print-file-name=libm.a
返回:
/usr/lib/gcc/x86_64-linux- gnu/9/../../../x86_64-linux-gnu/libm.a


但是我找不到它。在当前目录(/usr/lib/gcc/x86_64-linux-gnu/9):我执行ls命令,返回以下内容:

cc1          crtfastmath.o      finclude           libcaf_single.a  libgfortran.spec  liblsan.so              libobjc_gc.so       libsupc++.a
cc1plus      crtoffloadbegin.o  include            libcc1.so        libgomp.a         liblsan_preinit.o       libquadmath.a       libtsan.a
collect2     crtoffloadend.o    libasan.a          libgcc.a         libgomp.so        liblto_plugin.so        libquadmath.so      libtsan.so
crtbegin.o   crtoffloadtable.o  libasan.so         libgcc_eh.a      libgomp.spec      liblto_plugin.so.0      libsanitizer.spec   libubsan.a
crtbeginS.o  crtprec32.o        libasan_preinit.o  libgcc_s.so      libitm.a          liblto_plugin.so.0.0.0  libssp_nonshared.a  libubsan.so
crtbeginT.o  crtprec64.o        libatomic.a        libgcov.a        libitm.so         libobjc.a               libstdc++.a         lto-wrapper
crtend.o     crtprec80.o        libatomic.so       libgfortran.a    libitm.spec       libobjc.so              libstdc++.so        lto1
crtendS.o    f951               libbacktrace.a     libgfortran.so   liblsan.a         libobjc_gc.a            libstdc++fs.a       plugin

只有finclude、include、plugin是目录。我已经检查过 libm.a 不存在。

为什么要打扰,因为基于此链接。(https://www.linuxtopia.org/online_books/an_introduction_to_gcc/gccintro_17.html)如果我找到正确的 libm.a 完整路径,我应该能够执行以下命令。

gcc -Wall calc.c /usr/lib/libm.a -o calc

但是以下命令仍然有效。

gcc -Wall calc.c -lm -o calc
gcc
  • 1 个回答
  • 64 Views
Martin Hope
Jingqiang Zhang
Asked: 2022-05-23 00:10:08 +0800 CST

如何在 debian 11 上安装 gcc 和 build-essential?

  • 0

在/etc/apt/sources.list中,允许的来源是

deb http://deb.debian.org/debian buster main contrib non-free
deb http://deb.debian.org/debian-security/ buster/updates main contrib non-free
deb http://deb.debian.org/debian buster-updates main contrib non-free
deb http://emacs.ganneff.de/ buster main

我安装了这些软件包

$ sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

其中一些无法安装。输出消息是

Hit:1 http://deb.debian.org/debian buster InRelease
Hit:2 http://deb.debian.org/debian-security buster/updates InRelease
Hit:3 http://deb.debian.org/debian buster-updates InRelease
Hit:4 http://emacs.ganneff.de buster InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
curl is already the newest version (7.64.0-4+deb10u2).
make is already the newest version (4.2.1-1.2).
make set to manually installed.
wget is already the newest version (1.21-1+deb11u1).
xz-utils is already the newest version (5.2.5-2.1~deb11u1).
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 dpkg-dev : Depends: libdpkg-perl (= 1.19.7) but 1.20.9 is to be installed
        Recommends: fakeroot
        Recommends: libalgorithm-merge-perl but it is not going to be installed
 g++ : Depends: cpp (= 4:8.3.0-1) but 4:10.2.1-1 is to be installed
 gcc : Depends: cpp (= 4:8.3.0-1) but 4:10.2.1-1 is to be installed
 libbz2-dev : Depends: libbz2-1.0 (= 1.0.6-9.2~deb10u1) but 1.0.8-4 is to be installed
          Recommends: bzip2-doc but it is not going to be installed
 libc6-dev : Depends: libc6 (= 2.28-10+deb10u1) but 2.31-13+deb11u2 is to be installed
         Depends: libc-dev-bin (= 2.28-10+deb10u1) but it is not going to be installed
 libfontconfig1-dev : Depends: libfontconfig1 (= 2.13.1-2) but 2.13.1-4.2 is to be installed
                  Depends: libexpat1-dev but it is not going to be installed
                  Depends: uuid-dev but it is not going to be installed
 libfreetype6-dev : Depends: libfreetype6 (= 2.9.1-3+deb10u2) but 2.10.4+dfsg-1 is to be installed
                Depends: libpng-dev but it is not going to be installed
 liblzma-dev : Depends: liblzma5 (= 5.2.4-1+deb10u1) but 5.2.5-2.1~deb11u1 is to be installed
 libncurses-dev : Depends: libtinfo6 (= 6.1+20181013-2+deb10u2) but 6.2+20201114-2 is to be installed
              Depends: libncurses6 (= 6.1+20181013-2+deb10u2) but 6.2+20201114-2 is to be installed
              Depends: libncursesw6 (= 6.1+20181013-2+deb10u2) but 6.2+20201114-2 is to be installed
 libncursesw5-dev : Depends: libtinfo6 (= 6.1+20181013-2+deb10u2) but 6.2+20201114-2 is to be installed
 libsqlite3-dev : Depends: libsqlite3-0 (= 3.27.2-3+deb10u1) but 3.34.1-3 is to be installed
 libssl-dev : Depends: libssl1.1 (= 1.1.1n-0+deb10u2) but 1.1.1n-0+deb11u2 is to be installed
 libx11-dev : Depends: libx11-6 (= 2:1.6.7-1+deb10u2) but 2:1.7.2-1 is to be installed
          Depends: libxau-dev (>= 1:1.0.0-1) but it is not going to be installed
          Depends: libxcb1-dev but it is not going to be installed
 libxext-dev : Depends: libxext6 (= 2:1.3.3-1+b2) but 2:1.3.3-1.1 is to be installed
 libxml2-dev : Depends: libxml2 (= 2.9.4+dfsg1-7+deb10u3) but 2.9.10+dfsg-6.7 is to be installed
 libxmlsec1-dev : Depends: libgcrypt20-dev but it is not going to be installed
              Depends: libgnutls28-dev but it is not going to be installed
              Depends: libnss3-dev but it is not going to be installed
              Depends: libxmlsec1 (= 1.2.27-2) but 1.2.31-1 is to be installed
              Depends: libxmlsec1-nss (= 1.2.27-2) but 1.2.31-1 is to be installed
              Depends: libxslt1-dev (>= 1.0.20) but it is not going to be installed
 libxt-dev : Depends: libxt6 (= 1:1.1.5-1+b3) but 1:1.2.0-1 is to be installed
         Depends: libsm-dev but it is not going to be installed
 zlib1g-dev : Depends: zlib1g (= 1:1.2.11.dfsg-1+deb10u1) but 1:1.2.11.dfsg-2+deb11u1 is to be installed
E: Unable to correct problems, you have held broken packages.

为什么这么多依赖不匹配?如何安装它们?

debian gcc
  • 1 个回答
  • 1813 Views
Martin Hope
Flux
Asked: 2022-04-18 00:26:24 +0800 CST

当有 libfoo 的版本名称但没有 libfoo.so 时如何使用 -lfoo 进行链接

  • 0

假设/usr/lib/x86_64-linux-gnu/包含 libfoo:

  • libfoo.so.2-> libfoo.so.2.0.0(符号链接)
  • libfoo.so.2.0.0

值得注意的是libfoo.so.

假设有一个程序/usr/local/bin/sillyprog使用类似gcc somefile.c -lfoo. 每次我尝试使用sillyprog时,它都会失败,/usr/bin/ld: cannot find -lfoo因为libfoo.so缺少。

假设我无权编辑其中的任何文件/usr,我可以使用哪些变通方法在运行时成功链接 libfoo sillyprog?

linux gcc
  • 1 个回答
  • 46 Views
Martin Hope
Raven
Asked: 2022-03-17 07:34:09 +0800 CST

指定要使用的 libstdc++

  • 0

我想使用更新的 GCC 版本。因此,我编译了 GCC 10 并将其安装到非标准目录/software/gcc10/中。到目前为止,一切都很好。

但是,当我真正想使用这个新版本的 GCC 时,我遇到了一些问题。我修改了我的PATH变量以包含/software/gcc10/bin/现在gcc --version确认系统找到我的新 GCC 10 编译器(而不是我系统的 GCC 8 编译器)。

但是,当我尝试使用此设置编译程序时,我收到有关未定义引用的错误std::filesystem,这应该是 GCC 10 的 libstdc++ 的一部分。我的假设是,虽然我现在使用的是更新的编译器,但链接器仍然希望链接到我系统的 libstdc++ 而不是/software/gcc10/lib64.

我尝试更改LD_LIBRARY_PATH以包含相应的目录,但这似乎没有任何效果。

检查gcc使用该-v选项运行的输出时,我偶然发现了LIBRARY_PATH环境变量,根据gcc 的文档,它的使用如下:

LIBRARY_PATH 的值是一个以冒号分隔的目录列表,很像 PATH。当配置为本地编译器时,如果 GCC 使用 GCC_EXEC_PREFIX 无法找到它们,则 GCC 在搜索特殊链接器文件时会尝试指定的目录。在为 -l 选项搜索普通库时,使用 GCC 进行链接也会使用这些目录(但首先使用 -L 指定的目录)。

事实上:LIBRARY_PATH相应地设置变量可以让我成功编译我的程序。但是,这似乎是一个特定于 gcc 的解决方案,我不禁想知道是否有更标准的方法来执行此操作(例如,这也会告诉 clang 在哪里寻找要链接的 C++ 标准库)?

更好的解决方案是使我的新 GCC 10 编译器始终使用 GCC 10 标准库,而系统的 GCC 8 编译器的调用将始终链接到系统 GCC 8 标准库。有没有办法告诉特定的编译器二进制文件它有一个应该使用的特定 stdlib?

libraries gcc
  • 1 个回答
  • 734 Views
Martin Hope
user135142
Asked: 2022-01-20 06:25:35 +0800 CST

因为 .*s 不像 gcc .*c 那样工作

  • 0

当我运行时gcc -c *.c,它运行:-

gcc -c file1.c -o file1.o
gcc -c file2.c -o file2.o
gcc -c file3.c -o file3.o
...

但as *.s运行: -

as file1.s -o a.out
as file2.s -o a.out
as file3.s -o a.out
...

默认情况下,gcc 在编译成目标文件时仅替换文件扩展名,但 gnu as 将默认文件输出设置为 a.out。如何使 gnu 在组装时将 .s 替换为 .o?

compiling gcc
  • 1 个回答
  • 26 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve