gpt4 book ai didi

c++ - "Cross-compatible"代码在 linux 中吐出错误并在 windows 上编译正常! (GLM)

转载 作者:行者123 更新时间:2023-11-28 07:29:38 31 4
gpt4 key购买 nike

我真的很惊讶,今天我下载了 Ubuntu 12 LTS 32 位并安装了 build essential。

然后我为我的项目创建了一个 makefile,我只是从互联网上的另一个项目复制粘贴并编辑了一些以启用 C++11 的东西,如果它需要 GLM 的东西?

无论如何生成文件:

GPP = g++
GCC = gcc
plugin_OUTFILE = "./QuaternionStuff.so"

COMPILE_FLAGS = -std=c++0x -m32 -O3 -fPIC -c -I ./ -w -D LINUX -D PROJECT_NAME=\"plugin\"

plugin = -D plugin $(COMPILE_FLAGS)

all: plugin

clean:
-rm -f *~ *.o *.so

plugin: clean
$(GPP) $(plugin) ./*.cpp
$(GPP) -std=c++0x -m32 --static -fshort-wchar -shared -o $(plugin_OUTFILE) *.o

现在,当我运行它时,linux 会吐出错误,我真的不明白它们......

现在,代码可以在 Windows 上运行,可以在最高警告级别等情况下正常编译,非常好!

但是 g++ 程序对此有点不满意:

no matching function for call to ‘GetPitchYawBetweenCoords(glm::vec3, glm::vec3, glm::vec2&)’
note: glm::vec2 GetPitchYawBetweenCoords(glm::vec3&, glm::vec3&)
note: candidate expects 2 arguments, 3 provided

//prototypes:
inline glm::vec2 GetPitchYawBetweenCoords(glm::vec3 &source, glm::vec3 &target);
inline void GetPitchYawBetweenCoords(glm::vec3 &source, glm::vec3 &target, glm::vec2 &output);

以及代码,以及调用它的相应函数:

//the call
inline void AmxSetVector3(AMX * amx, cell * &params, unsigned char startpos, glm::vec3 vector)
{
//some code here
}

inline void AmxSetVector2Inverse(AMX * amx, cell * &params, unsigned char startpos, glm::vec2 vector)
{
//some code here
}

static cell AMX_NATIVE_CALL GetPitchYawBetweenPositions( AMX* amx, cell* params )
{
glm::vec2 rot;
GetPitchYawBetweenCoords(AmxGetVector3(params,1),AmxGetVector3(params,4),rot);
AmxSetVector2Inverse(amx,params,7,rot);
return 1;
}

它怎么能区分这两个非常不同的功能(原型(prototype))呢?这是所有错误中最令人困惑的部分,但还有更多:(

我看不出有什么问题。

所以,我所做的是:我改变(非常痛苦,因为现在我的代码变得古怪,因为我需要改变一切只是为了 linux 发行版)不同名称的函数,我只是在第二个原型(prototype)结束,但又出现了一大堆错误..

In function ‘cell SomeFunction(AMX*, cell*)’:
error: invalid initialization of non-const reference of type ‘glm::vec3&
{aka glm::detail::tvec3<float>&}’ from an rvalue of type ‘glm::detail::tvec3<float>’

这又是......在同一个函数上......:

static cell AMX_NATIVE_CALL GetPitchYawBetweenPositions( AMX* amx, cell* params )
{
glm::vec2 rot;
GetPitchYawBetweenCoords(AmxGetVector3(params,1),AmxGetVector3(params,4),rot);
AmxSetVector2Inverse(amx,params,7,rot);//HERE
return 1;
}

这是怎么回事?我不知道如何解决这个问题..

G++版本为4.6

最佳答案

显然,AmxGetVector3返回 glm::detail::tvec3<float> .
根据标准,这个临时对象不能绑定(bind)到非常量引用(这是第二条消息试图告诉你的)。

不幸的是,Visual C++ 有一个愚蠢的非标准扩展,默认情况下启用,它允许这种绑定(bind)。

更改您的函数以具有这些(const-correct)原型(prototype):

inline glm::vec2 GetPitchYawBetweenCoords(const glm::vec3 &source, const glm::vec3 &target);
inline void GetPitchYawBetweenCoords(const glm::vec3 &source, const glm::vec3 &target, glm::vec2 &output);

关于c++ - "Cross-compatible"代码在 linux 中吐出错误并在 windows 上编译正常! (GLM),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17985432/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com