我正在尝试在OSX Lion上安装Imagemagick,但有些东西没有按预期工作.
-> brew install imagemagick
/usr/local/git/bin/git
==> Cloning https://github.com/adamv/ImageMagick.git
Cloning into /Users/klebershimabuku/Library/Caches/Homebrew/imagemagick--git...
fatal: https://github.com/adamv/ImageMagick.git/info/refs not found: did you run git update-server-info on the server?
Error: Failure while executing: git clone --depth 1 https://github.com/adamv/ImageMagick.git /Users/kleber/Library/Caches/Homebrew/imagemagick--git
Run Code Online (Sandbox Code Playgroud)
布鲁医生说:
-> brew doctor
We couldn't detect gcc 4.0.x. Some formulae require this compiler.
Some "config" scripts were found in your path, but not in system or Homebrew folders.
`./configure` scripts often look for *-config scripts to determine if software packagesare installed, and what additional …Run Code Online (Sandbox Code Playgroud) GCC 4.x不接受--std=c++14C++ 14代码的切换 - 它需要--std=c++1y代替.以后的版本需要(--std=c++1z但可能)--std=c++17还没有设置(2016年写这个).也许C++ 11也存在类似的问题.
CMake是否有一些设施(可能作为模块)根据GCC版本传递正确的开关?
boost::posix_time::ptime parseDate(const std::string& format, const std::string& localDate)
{
std::istringstream is(localDate);
is.imbue(std::locale(is.getloc(), new boost::local_time::local_time_input_facet(format.c_str())));
boost::posix_time::ptime pt;
is >> pt;
if (pt == boost::posix_time::ptime())
{
throw std::runtime_error("Parse error");
}
return pt;
}
Run Code Online (Sandbox Code Playgroud)
此函数应采用日期和格式字符串和return boost::posix_time::ptime.
例如:2012:06:14 02:50:58和%Y:%m:%d %H:%M:%S.
但是,如果我在多线程程序中调用它,有时抛出异常,虽然format并且localDate是正确且可解析的(我对每次调用都使用相同的日期).我发现了一些关于std::stringstream/ std::locale线程问题但没有更新的东西(我正在使用gcc 4.6.3 64位).
这里有人有同样的问题:
使用Valgrind/drd测试过去几天,我发现我的代码中有很多部分会导致问题.例如,当调用一些提升日期时间转换函数时,我点击std :: locale(),这不是线程安全的.
更新的代码没有问题:
boost::posix_time::ptime parseDate(const std::string& format, const std::string& localDate)
{
std::istringstream is(localDate);
auto* facet = new boost::local_time::local_time_input_facet(format.c_str());
{
boost::unique_lock<boost::mutex> lock(globalLocaleMutex);
is.imbue(std::locale(is.getloc(), facet));
}
boost::posix_time::ptime …Run Code Online (Sandbox Code Playgroud) 我正在编译MinGW GCC 4.4.0中的一些c ++代码,并使用以下表单获取警告......
warning: invalid access to non-static data member '<membername>' of NULL object
warning: (perhaps the 'offsetof' macro was used incorrectly)
Run Code Online (Sandbox Code Playgroud)
这个问题似乎很熟悉 - 我想,之前我曾试图解决这个问题,但我想,但不久之前.代码在Visual C++中构建得很好,但我最近没有在任何其他编译器中构建这个特定的代码.
问题代码是以下模板......
template<typename T>
class c_Align_Of
{
private:
struct c_Test
{
char m_Char;
T m_Test;
};
public:
enum { e_Align = offsetof (c_Test, m_Test) };
};
Run Code Online (Sandbox Code Playgroud)
显然,我可以使用一些条件编译来为此使用特定于编译器的函数,我相信C++ 0x(最后)会使它变得多余.但无论如何,我看不出这种用法有什么不妥offsetof.
非常迂腐,有可能因为T参数类型有时是非POD,所以GCC类c_Test作为非POD和抱怨(抱怨和抱怨 - 我得到近800行这些警告).
由于非POD类型可能会破坏,因此标准的严格措辞令人顽皮offsetof.但是,这种非POD在实践中应该不是问题 - c_Test不会有虚拟表,也不需要运行时技巧来查找偏移量m_Test.
此外,即使c_Test有一个虚拟表,GCC 也会使用内部函数实现offsetof宏,该内部函数总是在编译时根据该特定类型的静态布局进行求值.提供一个工具,然后每次使用时抱怨(抱歉,警告)似乎很愚蠢.
另外,我不是这里唯一一个做这种事的人......
我确实 …
Gentoo Wiki告诉我以下内容:
警告:GCC 4.2及以上版本支持-march = native.-march = native应用超出-march的其他设置,特定于CPU.除非您有特殊原因(例如,distcc交叉编译),否则您应该使用-march = native,而不是下面列出的任何内容.
那些额外的设置是什么?
使用gcc版本4.3.2时,我看到如何使用以下命令生成规范:
$ /usr/local/gcc-4.3.2/bin/gcc -v
Using built-in specs
Run Code Online (Sandbox Code Playgroud)
现在更改为与libgcc相同的目录:
cd /usr/local/gcc-4.3.2/lib/gcc/x86_64-unknown-linux-gnu/4.3.2
/usr/local/gcc-4.3.2/bin/gcc -dumpspecs > specs
Run Code Online (Sandbox Code Playgroud)
我有一个我可以修改的填充规范文件.但是,一旦完成,我仍然看到:
$ /usr/local/gcc-4.3.2/bin/gcc -v
Using built-in specs
Run Code Online (Sandbox Code Playgroud)
我如何告诉gcc默认使用该specs文件而不是强迫我在-specs每次编译时传递一个参数?我希望它与我拥有的另一个系统匹配,我得到以下内容:
$ /usr/local/gcc-4.3.2/bin/gcc -v
Reading specs from /usr/local/gcc-4.3.2/lib/gcc/i686-pc-linux-gnu/4.3.2/specs</code>
Run Code Online (Sandbox Code Playgroud)
如您所见,两个系统之间的主要区别在于现有设置是32位,我现在正尝试在64位系统上进行匹配.Linux的版本是相同的,我正在编译相同版本的gcc.(两个系统gcc 4.3.2是第二个gcc安装,4.1.2用于编译4.3.2)
请考虑以下代码:
template < typename T >
struct A
{
struct B { };
};
template < typename T >
void f( typename A<T>::B ) { }
int main()
{
A<int>::B x;
f( x ); // fails for gcc-4.1.2
f<int>( x ); // passes
return 0;
}
Run Code Online (Sandbox Code Playgroud)
所以这里gcc-4.1.2要求f明确指定模板参数.这符合标准吗?较新版本的GCC是否修复了此问题?如何避免int在调用时明确指定f?
更新: 这是一个解决方法.
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_same.hpp>
template < typename T >
struct A
{
typedef T argument;
struct B { typedef A outer; };
};
template < …Run Code Online (Sandbox Code Playgroud) 我正在使用C库(来自C++),它提供以下接口:
void register_callback(void* f, void* data);
void invoke_callback();
Run Code Online (Sandbox Code Playgroud)
现在,我需要注册一个函数模板作为回调,这导致我的问题.请考虑以下代码:
template <typename T> void my_callback(void* data) { … }
int main() {
int ft = 42;
register_callback(reinterpret_cast<void*>(&my_callback<int>), &ft);
invoke_callback();
}
Run Code Online (Sandbox Code Playgroud)
这给了我以下链接器错误(在OS X上使用g ++(GCC)4.5.1,但适用于编译器版本/平台的大多数其他组合):
架构x86_64的未定义符号:
Run Code Online (Sandbox Code Playgroud)"void my_callback<int>(void*)", referenced from: _main in ccYLXc5w.o
我觉得这是可以理解的.
通过显式实例化模板可以轻松解决此问题:
template void my_callback<int>(void* data);
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不适用于我的真实代码,因为回调是在函数模板中注册的,我不知道这个函数将被调用哪个模板参数集,因此我不能为所有的函数提供显式实例化.他们(我正在编写一个图书馆).所以我的真实代码看起来有点像这样:
template <typename T>
void do_register_callback(T& value) {
register_callback(reinterpret_cast<void*>(my_callback<T>), &value);
// Other things …
}
int main() {
int ft = 42;
do_register_callback(ft);
invoke_callback();
}
Run Code Online (Sandbox Code Playgroud)
通过调用函数隐式实例化函数模板.所以我们这样做,但要确保调用没有实际执行(该函数有副作用): …
我将应用程序移植到C中的ARM平台,该应用程序也在x86处理器上运行,并且必须向后兼容.
我现在有一些变量对齐的问题.我已经阅读了gcc手册,因为
__attribute__((aligned(4),packed))我解释了所说的内容,因为struct的开头与4字节边界对齐,并且由于packed语句,内部保持不变.
最初我有这个,但偶尔它与4字节边界不对齐.
typedef struct
{
unsigned int code;
unsigned int length;
unsigned int seq;
unsigned int request;
unsigned char nonce[16];
unsigned short crc;
} __attribute__((packed)) CHALLENGE;
Run Code Online (Sandbox Code Playgroud)
所以我把它改成了这个.
typedef struct
{
unsigned int code;
unsigned int length;
unsigned int seq;
unsigned int request;
unsigned char nonce[16];
unsigned short crc;
} __attribute__((aligned(4),packed)) CHALLENGE;
Run Code Online (Sandbox Code Playgroud)
该明白我前面所说似乎是不正确的,这两个结构是现在对齐到4字节边界,和现在的内部数据对齐到四个字节边界,但因为尾结构,该结构的大小已增加大小从42到44个字节.这个大小是至关重要的,因为我们有其他依赖于结构为42字节的应用程序.
有些人可以向我描述如何执行我需要的操作.任何帮助深表感谢.
gcc信息文件在x86-64特定标志的部分中说明,其中包括:
There is no `-march=generic' option because `-march'
indicates the instruction set the compiler can use, and there
is no generic instruction set applicable to all processors.
In contrast, `-mtune' indicates the processor (or, in this
case, collection of processors) for which the code is
optimized.
Run Code Online (Sandbox Code Playgroud)
我的问题是,当没有给出-march选项时,gcc编译的指令(子)集是什么?在webosphere中有很多关于-march和-mtune的相关信息,但我找不到哪个能回答这个简单的问题.它不能是march = native,否则就不可能编译通用分发内核和二进制包.