编译在Windows和Linux [英] compiling on windows and linux

查看:166
本文介绍了编译在Windows和Linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的C和我有一些被赋予了某些源$ C ​​$ C,别人曾撰文指出,在Windows上编译。

I am new to c, and I have some been given some source code that someone else has written that was compiled on windows.

试图在编译Linux上我有错误,因为Linux不支持DWORD,Word和UINT32后。我有6个文件的例子。 A.H,交流转换器,B.h,B.c,C.h,C.C。这些关键字在所有的文件。

After trying to make in compile on linux I have errors because linux doesn't support DWORD, WORD, AND UINT32. I have 6 files for example. A.h, A.c, B.h, B.c, C.h, C.c. These keyword are in all the files.

所以,我想到的2可能的解决方案。哪个是更好的#define或typedef的。

So I am thinking of 2 possible solutions. Which is better #define or typedef.

1)

typedef unsigned long DWORD;
typedef unsigned short WORD;
typedef unsigned int UNINT32;

2)

#define DWORD unsigned long 
#define WORD unsigned short 
#define UINT32 unsigned int

有关的第二部分,我想知道我应该把这些声明。他们应该去的头文件,还是应该在源文件中去?

For the second part I am wondering where should I put these declarations. Should they go in the header files, or should they go in the source files?

例如,我应该做这样的事情在头文件中,还是在源文件?

For example should I do something like this in the header files, or in the source files?

#ifdef WIN32
/* windows stuff */
#else
typedef unsigned long DWORD;
typedef unsigned short WORD;
typedef unsigned int UNINT32;
#endif

非常感谢上述建议,

Many thanks for the above suggestions,

推荐答案

您已经找到了自己的解决方案:

You have found the solution yourself:

#ifdef WIN32
/* windows stuff */
#else
typedef unsigned long DWORD;
typedef unsigned short WORD;
typedef unsigned int UNINT32;
#endif

在一个单独的头文件(typedefs.h)将这个并将其包含来自世界各地。的typedef总是preferred超过pre处理器宏。

Put this in a separate header file (typedefs.h) and include it from everywhere. Typedef are always preferred over pre-processor macros.

我的建议:不要使用DWORD,WORD或其他的Win32类型。我通常preFER使用C99标准类型:uint_t,int_t或uint16_t,uint32_t的

My recommendation: Do not use DWORD, WORD or other Win32 types. I usually prefer to use C99 standard types: uint_t, int_t or uint16_t, uint32_t

这篇关于编译在Windows和Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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