1

我正在构建一个 c++ 项目,我需要支持多个平台。因为我主要使用 Linux,所以我也在尝试在 Linux 上为 Windows 编译项目。

我正在使用mingw编译器。它类似于 g++,但我在将libsodum库链接到我的项目时遇到问题。

我正在使用 cmake,但这是一个简单的代码补丁,它仍然会重现问题。

测试.cpp

#include <iostream>
#include <sodium.h>

int main() {
    if (sodium_init() == -1) {
        std::cout << "Sodoum init failed" << std::endl;
    } else {
        std::cout << "Success" << std::endl;
    }
    return 0;
}

在同一个文件夹中,我复制了libsodium-win64文件夹的内容,其中是libsodium. 现在看起来像这样:

.
├── bin
│   ├── libsodium-18.dll
│   └── libsodium-8.def
├── compile
├── include
│   ├── sodium
│   │   ├── core.h
│   │   ├── ... (and lot of other .h files)
│   │   └── version.h
│   └── sodium.h
├── lib
│   ├── libsodium.a
│   ├── libsodium.dll.a
│   ├── libsodium.la
│   └── pkgconfig
│       └── libsodium.pc
└── test.cpp

我现在正在尝试用mingw.

i686-w64-mingw32-g++ test.cpp \
-static-libstdc++ -static-libgcc \
-Llib -lsodium -Iinclude

这给我一个错误:

/tmp/ccyODazj.o:test.cpp:(.text+0x17): undefined reference to `sodium_init'
collect2: error: ld returned 1 exit status

我也尝试libsodium用 mingw 编译我自己的二进制文件,但这并没有解决问题。

4

0 回答 0