简体   繁体   English

在C中为跨平台(Linux)编译代码时出错

[英]Error compiling code in c for cross-platform (Linux)

The project code I need to compile is in C. The project compiles correctly in Visual Studio 2015 but I need to migrate it to linux (Ubuntu) and it gives me error of the following type: 我需要编译的项目代码在C中。该项目在Visual Studio 2015中可以正确编译,但是我需要将其迁移到linux(Ubuntu),并且出现以下类型的错误:

/jpeglib8.h:1011:8: error: expected '=', ',', ';', 'asm' or ' attribute ' before 'void' EXTERN (void) jpeg_CreateCompress JPP ((j_compress_ptr cinfo, /jpeglib8.h:1011:8:错误:预期在'void'EXTERN(void)之前出现'=',',',';','asm'或' attribute'jpeg_CreateCompress JPP(((j_compress_ptr cinfo,

1005    #define jpeg_create_compress(cinfo) \
1006        jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
1007                (size_t) sizeof(struct jpeg_compress_struct))
1008    #define jpeg_create_decompress(cinfo) \
1009        jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
1010                  (size_t) sizeof(struct jpeg_decompress_struct))
1011    EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
1012                          int version, size_t structsize));
1013    EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
1014                    int version, size_t structsize));

Apparently there is no syntax error. 显然没有语法错误。 I will really appreciate the help, thank you. 非常感谢您的帮助,谢谢。

EXTERN might be a macro which is defined and well preprocessed by your Visual Studio 2015 compiler. EXTERN可能是由Visual Studio 2015编译器定义并经过预处理的宏。 It looks like it is not or not well defined under your Linux compiler environment. 在您的Linux编译器环境下,它看起来似乎定义不正确。 In my opinion, you should: 我认为您应该:

  1. generate the intermediate preprocessed file and have a look on it 生成中间预处理文件并对其进行查看
  2. look at the EXTERN macro definition in your project 查看项目中的EXTERN宏定义

The EXTERN macro is often used to declare variables (allocate storage) or just define them (make them known). EXTERN宏通常用于声明变量(分配存储空间)或仅定义变量(使其已知)。 It works like this: 它是这样的:

// main.c
#define EXTERN
#include "myinclude.h"

// sub-module.c
#include "myinclude.h"

// myinclude.h
#ifndef EXTERN
#define EXTERN extern
#endif
EXTERN int myvar;
EXTERN void do_something(int a);

In the above, when myinclude.h is inluded in main.c , the directive EXTERN is set to nothing and so the variable int myvar will be allocated. 在上面的代码中,当main.c myinclude.h myinclude.h时,指令EXTERN设置为int myvar ,因此将分配变量int myvar In all other modules that include it, it will be set to extern and so only define the variable. 在所有其他包含它的模块中,它将被设置为extern ,因此仅定义变量。

For functions this is not necessary anymore with the advent of prototypes. 对于功能来说,原型的出现不再需要此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM