gpt4 book ai didi

c++ - 源代码错误,将交叉编译器从 gcc4.9.2 降级到 gcc4.4.1 后

转载 作者:太空宇宙 更新时间:2023-11-04 12:54:48 24 4
gpt4 key购买 nike

我目前正在研究 arm-unknown-linux-gnueabi 并将编译器从 gcc4.9.2 降级到 gcc4.4.1。我使用 crosstool-ng 来编译带有 gcc4.4.1 的编译器。如您所知,gcc4.9.2 比 gcc4.4.1 支持更多的 c++11 功能。代码在 4.9.2 中编译没有错误,但在 4.4.1 中面临错误。以下是我不明白为什么的错误?代码是,

#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <list>
#include <cassert>
#include <dlfcn.h>
#include <cstring>
#include <stdexcept>

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

提前致谢

错误是

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

最佳答案

您正在使用 C++11 特定代码,如果我没记错的话,第一个(部分)支持 C++11 的 gcc 版本是 4.7。编译器对 void * lib_hwnd {}; 有问题,统一初始化是 C++11。将其更改为 void* lib_hwnd = NULL; 并检查您的代码是否有任何其他 C++11 特定内容。

关于c++ - 源代码错误,将交叉编译器从 gcc4.9.2 降级到 gcc4.4.1 后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47054807/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com