I am currently working on arm-unknown-linux-gnueabi and downgraded compiler from gcc4.9.2 to gcc4.4.1. I used crosstool-ng to compile compiler with gcc4.4.1.As you know gcc4.9.2 supports more c++11 features then gcc4.4.1. Code was compiling with no errors with 4.9.2 but faces errors with 4.4.1. Following is the error which i can't understand why ? Code is,
class dl_loader {
// Dl loader
dl_loader( dl_loader& ) = delete;
dl_loader& operator=( dl_loader& ) = delete;
dl_loader() {
}
public:
~dl_loader() {
if (_instance_) {
delete _instance_; _instance_ = NULL;
}
}
public:
static dl_loader * get_instance();
//Resolve name by svc_net.so.1:name
template <typename Func, typename ...Args>
typename std::function<Func>::result_type call( const char* name, Args && ...args )
{
Func* fptr = reinterpret_cast<Func*>( find_or_load_symbol( name ) );
assert(fptr);
return fptr( args ... );
}
template <typename Func>
typename std::function<Func>::result_type call( const char* name )
{
Func* fptr = reinterpret_cast<Func*>( find_or_load_symbol( name ) );
assert(fptr);
return fptr( );
}
private:
//! Find or load symbol from the dynamic library
void* find_or_load_symbol( const char *name );
private:
std::map<std::string, void*> m_funcs; //Function loaded names
**// using lib_ptr_t = std::unique_ptr<void,std::function<void(void*)>>; IQ:b/c gcc4.4.1 doesn't support aliases keyword "using"
typedef std::unique_ptr<void ,std::function<void(void* )>> lib_ptr_t;**
std::map<std::string, lib_ptr_t> m_libs; //Libs loaded
static dl_loader * _instance_;
};
/! Find or load symbol from the dynamic library
void* dl_loader::find_or_load_symbol( const char *name )
{
const auto f_it = m_funcs.find( name );
if( f_it == m_funcs.end() )
{
const auto sep = std::strstr( name, ":" );
if( !sep )
{
throw std::logic_error("Invalid syntax token : not found");
}
const auto name_len = sep - name;
char library_name[ name_len + sizeof('\0') ];
std::memcpy( library_name, name, name_len );
library_name[name_len] = '\0';
const auto symbol_name = sep + 1;
const auto l_it = m_libs.find( library_name );
void* lib_hwnd {};
if( l_it == m_libs.end() )
{
const auto handle = dlopen( library_name, RTLD_LAZY );
if( !handle )
{
throw std::logic_error( std::string("Unable to find library: ") +
library_name );
}
// m_libs[ library_name ] = lib_ptr_t ( handle, [](void*d){ dlclose(d); } );
lib_hwnd = handle;
}
else
{
lib_hwnd = l_it->second.get();
}
//Try to open function name from library
const auto fn_ptr = dlsym( lib_hwnd, symbol_name );
if( fn_ptr )
{
m_funcs[ name ] = fn_ptr;
return fn_ptr;
}
else
{
throw std::logic_error( std::string("Unable to find symbol: ") +
symbol_name + " in library: " + library_name );
}
}
else
{
return f_it->second;
}
return NULL;
}
Thanks in Advance
Errors are
find_or_load_symbol(const char*)':
dynlib_loader.cpp:67: error: expected primary-expression before '(' token
dynlib_loader.cpp:68: error: expected primary-expression before '[' token
dynlib_loader.cpp:68: error: expected primary-expression before ']' token
dynlib_loader.cpp:68: error: expected primary-expression before 'void'
dynlib_loader.cpp:69: error: expected ')' before '{' token
dynlib_loader.cpp:69: error: expected ';' before ')' token
Aucun commentaire:
Enregistrer un commentaire