2011-09-15 36 views
5

Tôi muốn sử dụng thư viện C++ (glm.g-truc.net) chỉ có tiêu đề GLM trong dự án NDK của Android, nhưng tôi nhận được các lỗi biên dịch. Trong Android.mk, tôi đã thêm các đường dẫn tìm kiếm tiêu đềThư viện C++ tiêu đề (GLM) không biên dịch với Android-NDK

LOCAL_CFLAGS += -I/Users/Johannes/Development/glm_include/ 

và tôi cũng đã cố gắng để biên dịch sử dụng STLport và GNU-STL bằng cách thiết lập sau đây trong Application.mk như được mô tả trong tài liệu CPLUSPLUS-HỖ TRỢ:

APP_STL := stlport_static 

hoặc

APP_STL := gnustl_static 

tương ứng. Không có gì giúp; Đó là những lỗi tôi nhận được khi bao gồm <glm/glm.h> và sử dụng glm::ivec2. ndk-build kết quả đầu ra:

Compile++ arm : wbar <= QCARBase.cpp 
In file included from /Users/Johannes/Development/glm_include/glm/glm.hpp:66, 
       from /Users/Johannes/proj/WirtschaftsblattAR/app/android/wbar/jni/QCARBase.cpp:45: 
/Users/Johannes/Development/glm_include/glm/./core/func_common.hpp:240: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.hpp:240: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.hpp:240: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.hpp:251: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.hpp:251: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.hpp:251: error: expected ')' before 'sizeof' 
In file included from /Users/Johannes/Development/glm_include/glm/./core/func_common.hpp:335, 
       from /Users/Johannes/Development/glm_include/glm/glm.hpp:66, 
       from /Users/Johannes/proj/WirtschaftsblattAR/app/android/wbar/jni/QCARBase.cpp:45: 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1202: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1202: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1202: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1217: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1217: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1217: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1228: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1228: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1228: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1240: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1240: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1240: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1253: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1253: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1253: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1268: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1268: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1268: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1279: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1279: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1279: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1291: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1291: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1291: error: expected ')' before 'sizeof' 
make: *** [/Users/Johannes/proj/WirtschaftsblattAR/app/android/wbar/obj/local/armeabi/objs/wbar/QCARBase.o] Error 1 

Tôi đang sử dụng Crystax NDK r6 (www.crystax.net)

+0

Các bạn đã thử 'LOCAL_C_INCLUDES + =/Users/Johannes/Phát triển/glm_include/'thay vì LOCAL_CFLAGS? –

+0

Có, điều này có tác dụng tương tự. Trình biên dịch rõ ràng tìm thấy các tệp, bởi vì các lỗi ở trên nằm trong các tệp được bao gồm. – j00hi

+0

mã hiển thị trước khi bao gồm glm/glm.h – fazo

Trả lời

2

Bằng cách nào đó tôi đã quản lý để biên dịch nó. Xác định các tùy chọn sau trong Application.mk đã làm các trick:

APP_OPTIM := release 
APP_STL := stlport_static 
LOCAL_ARM_MODE := thumb 
APP_ABI := armeabi armeabi-v7a 

Và, tôi nghĩ rằng với STLport, bạn không thể sử dụng RTTI hoặc ngoại lệ, do đó, không cho phép -frtti hoặc -fexceptions trong Android.mk

1

Cố gắng xây dựng một ứng dụng thử nghiệm mẫu nhỏ như thế này:

#include <glm/glm.h> 
int main(int argc, char* argv[]) 
{ 
    return 0; 
} 

Liệu công việc đó?

Nếu có, thì tôi sẽ đặt cược rằng trong ứng dụng của bạn, bạn có glm.h của bạn bao gồm sau một số #define có một va chạm biểu tượng với một biểu tượng được sử dụng trong glm. #define của bạn có thể sử dụng từ khóa sizeof và được thay thế trong các dòng glm có lỗi.

Một giải pháp có thể là di chuyển glm.h bao gồm trên bất kỳ #includes và/hoặC#defines khác, nếu bạn đặt nó là điều đầu tiên trong tệp bạn có thể bỏ qua vấn đề.

Một giải pháp tốt hơn là cố gắng tránh #defines và sử dụng các hàm nội tuyến bất cứ khi nào có thể.

Tôi hy vọng điều này sẽ hữu ích.

+0

Tôi đã thử điều đó - chỉ bao gồm '', nhưng tôi vẫn gặp phải các lỗi tương tự. Nó có thể là một vấn đề trình biên dịch? Nó dường như không có hiệu lực, thay đổi thư viện STL. – j00hi

+0

Tôi đã thử nghiệm GLM trên 2,3+ (mục tiêu API-10) trong ứng dụng NDK (r5c và r6b) và nó hoạt động tốt. Có lẽ Crystax là một vấn đề? – kibab

0

Tôi đang gặp sự cố tương tự khi tôi cố gắng biên dịch glm chống lại gnustl_static, nhưng tôi không gặp bất kỳ sự cố nào khi tôi cố gắng biên dịch với stlport_static. Đề xuất duy nhất của tôi là thử khai báo phụ thuộc stlport bằng cách sử dụng LOCAL_STATIC_LIBRARIES trong mô-đun thư viện được chia sẻ của bạn.

Ngoài ra, bạn đã thử sử dụng stlport_shared chưa? stlport có cả thư viện chia sẻ và tĩnh, trong khi gnustl chỉ có phiên bản tĩnh (nhưng hỗ trợ ngoại lệ/RTTI).

3

Sau một chút nhảy đầu, tôi đã tìm ra cách sửa lỗi này bằng thời gian chạy GNU libstdC++.

Cố gắng xác định _GLIBCXX_USE_C99_MATH-1 trước bao gồm <glm.hpp>, như thế này:

#define _GLIBCXX_USE_C99_MATH 1 
#include <glm/glm.hpp> 

<glm.hpp> bao gồm <cmath>, mà lần lượt bao gồm <math.h>. Các _GLIBCXX_USE_C99_MATH lực lượng vĩ mô <cmath> để #undef một số macro từ <math.h> mà nếu không sẽ ẩn một số chức năng như glmisnan(), isinf() vv

Các vấn đề liên quan