Gizmo
Gizmo

Reputation: 2210

"Cross-compatible" code spits errors in linux and compiles fine on windows! (GLM)

I'm really surprised, today I downloaded Ubuntu 12 LTS 32bit and installed build essential.

Then I created a makefile for my project which I just copy pasted from another project from the internet and edited a bit to enable C++11 stuff if it's needed for GLM stuff?

anyway the makefile:

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

now, when I run it, linux spits there errors out and I seriously don't understand them..

Now, the code works on windows, compiles fine with highest warning level etc, and it's good!

But the g++ program is somewhat not happy with this:

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);

And the code, with the according functions which calls it:

//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;
}

How the hell can it not distinguishsuch two very different functions (prototypes)? This is the most confusing part of all the errors, but there is more :(

I don't see anything that is wrong with that.

So, what I do is: I change (with big pain, because now my code gets quircky because I need to change everything just for the linux distirbution) the functions to different names, I just added an 'R' to the end of the second prototype, but then another ton of errors come up..

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>’

and that's again.. on the same function...:

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;
}

What is going on? I have no idea how to fix this..

The G++ version is 4.6

Upvotes: 0

Views: 284

Answers (1)

molbdnilo
molbdnilo

Reputation: 66451

Apparently, AmxGetVector3 returns a glm::detail::tvec3<float>.
According to the standard, this temporary object can't be bound to a non-const reference (this is what the second message is trying to tell you).

Unfortunately, Visual C++ has a silly non-standard extension, enabled by default, that allows that kind of binding.

Change your functions to have these (const-correct) prototypes:

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);

Upvotes: 1

Related Questions