C++编译NumCpp过程中的问题

由于在python中的代码依赖numpy库,转到C++后,需要重新安装numpy的C++版本(NumCpp),地址为:

dpilger26/NumCpp: C++ implementation of the Python Numpy library (github.com)icon-default.png?t=N7T8https://github.com/dpilger26/NumCpp按照官方只是安装编译完成后,运行测试代码

#include "NumCpp.hpp"
#include <cstdlib>
#include <iostream>

int main()
{
    auto a = nc::random::randInt<int>({10, 10}, 0, 100);
    std::cout << a;

    return EXIT_SUCCESS;
}

报错:

D:/clion2024-1-4/CLion 2024.1.4/bin/mingw/x86_64-w64-mingw32/include/time.h:264:55: note: initializing argument 1 of 'errno_t gmtime_s(tm*, const time_t*)' 264 | static __inline errno_t __CRTDECL gmtime_s(struct tm *_Tm, const time_t *_Time) { return _gmtime64_s(_Tm, _Time); } | ~~~~~~~~~~~^~~ D:/island_project/NumCpp/include/NumCpp/DateTime/DateTime.hpp: In member function 'std::string nc::DateTime::toStr() const': D:/island_project/NumCpp/include/NumCpp/DateTime/DateTime.hpp:374:22: error: cannot convert 'time_t*' {aka 'long long int*'} to 'tm*' 374 | gmtime_r(&secondsFromEpoch, &tm); | ^~~~~~~~~~~~~~~~~ | | | time_t* {aka long long int*} D:/clion2024-1-4/CLion 2024.1.4/bin/mingw/x86_64-w64-mingw32/include/time.h:264:55: note: initializing argument 1 of 'errno_t gmtime_s(tm*, const time_t*)' 264 | static __inline errno_t __CRTDECL gmtime_s(struct tm *_Tm, const time_t *_Time) { return _gmtime64_s(_Tm, _Time); } | ~~~~~~~~~~~^~~ ninja: build stopped: subcommand failed.

在网上查找相关资料后,发现缺少boost库,于是 跟着(网站链接)网上的教程(配置和编译boost库后,还是会继续报错,显示boost无法安装,在网上找了好多方法后,还是无法安装编译成功boost(boost是numcpp的依赖库,必须先安装编译成功boost!)。最后实在没办法直接使用vcpkg安装,过程比较长,但是总算安装成功了。之后重新编译NumCpp,运行测试代码,依旧报上面的错误!!!

最终解决方案:在测试代码上面使用了条件编译来重新定义gmtime_r,使其参数顺序与gmtime_s一致。同时也重新定义了timegm_mkgmtime;

#ifdef _WIN32
#define gmtime_r(time, result) gmtime_s(result, time)
#define timegm _mkgmtime
#endif

#include "NumCpp.hpp"
#include <cstdlib>
#include <iostream>

int main()
{
    auto a = nc::random::randInt<int>({10, 10}, 0, 100);
    std::cout << a;

    return EXIT_SUCCESS;
}

 参考资料:

1. C++ vcpkg_vcpkg安装boost-CSDN博客

2. VS2022配置编译使用boost库_vs2022 boost库-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值