2013-11-26 24 views
1

我有一個模板類的頭文件.HPP:C++模板類的顯式實例與海灣合作委員會未能/ NDK

Rage.hpp:

//various includes... 

template<typename... Args> 
class Rage : public PlatformManagerDelegate 
{ 
    bool paused; 

    //other variables... 

public: 
    Rage(Args... args); 
    void pushInitialState(std::unique_ptr<State> state); 

    //other methods... 
}; 

,它是在源的.cpp實現文件,用明確的情況下,在文件的結尾:

Rage.cpp

#include "Rage.hpp" 
#include <android_native_app_glue.h> 
//other includes... 

template<typename... Args> 
Rage<Args...>::Rage(Args... args) : paused(false) 
{ 
    //some code... 
} 

template<typename... Args> 
void Rage<Args...>::pushInitialState(std::unique_ptr<State> state) 
{ 
    //some more code... 
} 

//more methods... 

template class Rage<>; 
template class Rage<struct android_app*>; 

編譯在main.cpp中

#include "Rage.hpp" 
#include <android_native_app_glue.h> 

void android_main(struct android_app* appState) 
{ 
    app_dummy(); 

    Rage<>* clientInstance = new Rage<>(); 
    clientInstance->beginRun(); 
} 

下面給出:使用MSVC從Visual Studio 2013(明顯改變android_main標準的主要功能)

undefined reference to 'Rage<>::beginRun()' 
undefined reference to 'Rage<>::Rage()' 

此代碼編譯完全正常,所以任何幫助,我似乎做錯了,讓它在GCC/NDK編譯將不勝感激!

+0

你如何鏈接代碼? –

+0

我沒有改變任何與鏈接有關的事情,所以不知道tbh,我應該發佈我的Android.mk和Application.mk?其他一切似乎都很好(內部項目和外部項目)。 – Rajveer

+0

不是,只是連接線。 –

回答

1

我不是Android開發人員,所以我不能重現問題。從基本的C++角度來看,它看起來好像具有實例的文件不包含在構建中。那麼,這涵蓋了缺少的構造函數實例。成員beginRun()根本沒有定義,但我假設它只是在複製代碼時被剪切,實際上在Rage.cpp中定義。

+0

我是個白癡,我有'FILE_LIST:= $(通配符$(LOCAL_PATH)/../../ source/*。 (LOCAL_PATH)/../../ source/android/*。cpp)' 'LOCAL_SRC_FILES \t:= $(FILE_LIST:$(LOCAL_PATH)/%=%) '而不是第二個使用+ =的FILE_LIST,所以只有我的平臺特定代碼正在構建中(其中包括main.cpp),同時模板化了我的Rage類,以便立即假定它是這樣的。謝謝! – Rajveer

相關問題