Question

I am trying to compile my OpenGL application in Android. I'm using [GLM library] (0.9.4)1

The compilation works until I include:

#include <glm/glm.hpp>

This header add cmath and linker complain about:

cmath:102:11: error: '::acos' has not been declared
...
cstdio:107:11: error: '::fprintf' has not been declared

It seems like std have some problem with using std, or libc++ of flags configuration on CMakeLists.txt

My CMakeLists.txt is:

status("")
status("* Adding module Core C++ ")

SET(PROJ_NAME CORE_CPP)
PROJECT(${PROJ_NAME})

# Helper to set libs & bin paths
INCLUDE(${PATH_MAIN}/cmake_tools/scripts/helperPaths.cmake)

# Include header from Module Core
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include )

IF(DEP_GLM)
  INCLUDE_DIRECTORIES( ${PATH_GLM} )
ENDIF(DEP_GLM)

# Source
#---------------------------------------------------#
file(GLOB CORE_CPP_SRC
    "src/*.cpp"
)
file(GLOB CORE_CPP_HEADERS
    "include/*.h"
)


# Create Library
ADD_LIBRARY(${PROJ_NAME} STATIC ${CORE_CPP_SRC} ${CORE_CPP_HEADERS})
#message("Link: ${LIBRARY_DEPS}")
SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic -fPIC" )
SET( LIBRARY_DEPS GLESv2 log android)
TARGET_LINK_LIBRARIES(${PROJ_NAME}  ${LIBRARY_DEPS})

status("- module ${PROJ_NAME} added! ")
  • In previous versions of gcc, It was needed to add #define _GLIBCXX_USE_C99_MATH 1 inside its includes, but it is already added in my version (4.8)

Any idea what is the problem?

Was it helpful?

Solution

I have found the problem, I was including the header INSIDE my namespace, so linker was looking for another namespace into std.

#ifndef MYNAME_MATH_H
#define MYNAME_MATH_H

#include <glm/glm.hpp>  // Linker Work

namespace myname
{
    //#define _GLIBCXX_USE_C99_MATH 1
    //#include <glm/glm.hpp> // Make linker FAIL!

    //typedef glm::vec2 Vector2;
    //typedef glm::vec3 Vector3;
    //typedef glm::vec4 Vector4;
}

#endif // MYNAME_MATH_H
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top