C ++ -malign-double编译器标志 [英] C++ -malign-double compiler flag

查看:376
本文介绍了C ++ -malign-double编译器标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些关于c ++编译器标志的帮助。我使用的库是一个端口到Linux的linux,必须使用-malign-double标志,为Win32兼容性编译。这是我的理解,这意味着我绝对必须编译自己的代码与这个标志吗?如何其他.so共享库,他们已经重新编译与此标志吗?如果是这样,有什么办法吗?

I need some help on compiler flags in c++. I'm using a library that is a port to linux from windows, that has to be compiled with the -malign-double flag, "for Win32 compatibility". It's my understanding that this mean I absolutely have to compile my own code with this flag as well? How about other .so shared libraries, do they have be recompiled with this flag as well? If so, is there any way around this?

我是一个linux新手(和c ++),所以即使我试图重新编译我使用的所有库对于我的项目,只是太复杂,递归找到所有的库和它们依赖的库的源,并重新编译一切。

I'm a linux newbie (and c++), so even though I tried to recompile all the libraries I'm using for my project, it was just too complicated to recursively find the source for all the libraries and the libraries they're dependent on, and recompile everything.

编辑:
感谢您的答案。一些背景:此库控制对USB连接的摄像机的初始化和访问。问题是,没有这个标志,奇怪的事情开始发生。看来随机,相机的初始化失败,与USB连接错误。我也得到一些类型的内存损坏的几个c字符串(const char *)在堆栈。基本上,在我调用这台摄像机的初始化之前,他们指向一个目录路径;在初始化之后,他们指向字符串me。

Thanks for the answers. Some background: This library controls the initialization and access to a USB-connected camera. The problem is that without this flag, weird things start to happen. Seemingly at random, the initialization of the camera fails, with USB connection errors. I also get some kind of memory corruption of several c-strings (const char*) that are on the stack. Basically, before I call the initialization of this camera, they point to a directory path; after the initialization, they point to the string "me". Which to me is very confusing.

推荐答案

您通常不需要更改现代编译器的对齐设置。
即使编译器会存储某些未对齐的,程序也不会被破坏。

You usually dont need to change alignment settings for modern compilers. Even if compiler will store someting unaligned, program will be not broken.

只有在需要的地方是在linux和windows版本之间传递的结构程序二进制(通过文件或通过网络)。但在这些情况下, pragma pack 的使用是更好的风格。

The only place where it can be needed is stuctures passed between linux and windows version of programm in binary (via files or via network). But in these cases the usage of pragma pack is better style.

更新:驱动程序还需要二进制结构逐位等于规格。

Update: drivers also require binary structures to be bit-by-bit equal with specification.

这篇关于C ++ -malign-double编译器标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆