2016-05-14 107 views
1

在我添加柠檬分析器之前,我的程序曾经用OpenBSD编译过。现在它编译在Linux上,但在OpenBSD上,我得到一个我不明白的错误。为什么我不能用OpenBSD编译?

$ cmake .. 
-- The C compiler identification is GNU 4.2.1 
-- The CXX compiler identification is GNU 4.2.1 
-- Check for working C compiler: /usr/bin/cc 
-- Check for working C compiler: /usr/bin/cc -- works 
-- Detecting C compiler ABI info 
-- Detecting C compiler ABI info - done 
-- Detecting C compile features 
-- Detecting C compile features - done 
-- Check for working CXX compiler: /usr/bin/c++ 
-- Check for working CXX compiler: /usr/bin/c++ -- works 
-- Detecting CXX compiler ABI info 
-- Detecting CXX compiler ABI info - done 
-- Detecting CXX compile features 
-- Detecting CXX compile features - done 
-- Configuring done 
-- Generating done 
-- Build files have been written to: /home/dac/test/openshell/build 
$ make 
Scanning dependScanning dependencies of target shell 
[ 28%] Building C object CMakeFiles/shell.dir/main.c.o 
/home/dac/test/openshell/main.c: In function 'main': 
/home/dac/test/openshell/main.c:788: warning: implicit declaration of function 'add_history' 
/home/dac/test/openshell/main.c: In function 'command': 
/home/dac/test/openshell/main.c:573: warning: passing argument 1 of 'expandVariable' discards qualifiers from pointer target type 
cc: -ledit: linker input file unused because linking not done 
cc: -lncurses: linker input file unused because linking not done 
cc: -lcurses: linker input file unused because linking not done 
cc: -ltermcap: linker input file unused because linking not done 
[ 42%] Building C object CMakeFiles/shell.dir/shellparser.c.o 
/home/dac/test/openshell/shellparser.c:280: error: expected expression before '%' token 
/home/dac/test/openshell/shellparser.c:288: error: expected expression before '%' token 
/home/dac/test/openshell/shellparser.c:288: error: initializer element is not constant 
/home/dac/test/openshell/shellparser.c:288: error: (near initialization for 'yyRuleName[0]') 
/home/dac/test/openshell/shellparser.c: In function 'yy_destructor': 
/home/dac/test/openshell/shellparser.c:370: error: expected expression before '%' token 
/home/dac/test/openshell/shellparser.c:370: warning: statement with no effect 
/home/dac/test/openshell/shellparser.c: In function 'yyStackOverflow': 
/home/dac/test/openshell/shellparser.c:551: error: expected expression before '%' token 
/home/dac/test/openshell/shellparser.c:551: warning: statement with no effect 
/home/dac/test/openshell/shellparser.c: At top level: 
/home/dac/test/openshell/shellparser.c:609: error: expected expression before '%' token 
/home/dac/test/openshell/shellparser.c:609: warning: missing braces around initializer 
/home/dac/test/openshell/shellparser.c:609: warning: (near initialization for 'yyRuleInfo[0]') 
/home/dac/test/openshell/shellparser.c:609: error: initializer element is not constant 
/home/dac/test/openshell/shellparser.c:609: error: (near initialization for 'yyRuleInfo[0].lhs') 
/home/dac/test/openshell/shellparser.c: In function 'yy_reduce': 
/home/dac/test/openshell/shellparser.c:664: error: expected expression before '%' token 
/home/dac/test/openshell/shellparser.c:664: warning: statement with no effect 
/home/dac/test/openshell/shellparser.c: In function 'yy_parse_failed': 
/home/dac/test/openshell/shellparser.c:710: error: expected expression before '%' token 
/home/dac/test/openshell/shellparser.c:710: warning: statement with no effect 
/home/dac/test/openshell/shellparser.c: In function 'yy_syntax_error': 
/home/dac/test/openshell/shellparser.c:726: error: expected expression before '%' token 
/home/dac/test/openshell/shellparser.c:726: warning: statement with no effect 
/home/dac/test/openshell/shellparser.c: In function 'yy_accept': 
/home/dac/test/openshell/shellparser.c:745: error: expected expression before '%' token 
/home/dac/test/openshell/shellparser.c:745: warning: statement with no effect 
/home/dac/test/openshell/shellparser.c: At top level: 
/home/dac/test/openshell/shellparser.c:918: error: expected identifier or '(' before string constant 
/home/dac/test/openshell/shellparser.c:929: error: expected identifier or '(' before ',' token 

为什么会发生,我该怎么办呢?我忘了包括图书馆吗?我cmake的文件是

cmake_minimum_required(VERSION 3.0) 
project(shell.test) 
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -L/usr/local/include/ -L/usr/include -std=c99 -pedantic -O3 -g -Wall -pedantic -ledit -lncurses -lcurses -ltermcap") 
include_directories(/usr/local/include/ /usr/include) 
link_directories(/usr/lib) 
link_directories(/usr/local/lib) 
add_executable(shell main.c shellparser.c errors.c util.c) 
target_link_libraries(shell edit readline) 
add_custom_target(shellparser DEPENDS ${CMAKE_SOURCE_DIR}/shellparser.c) 
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/shellparser.c COMMAND lemon -s ${CMAKE_SOURCE_DIR}/shellparser.y DEPENDS ${CMAKE_SOURCE_DIR}/shellparser.y) 
add_dependencies(shell shellparser) 
set_property(TARGET shell PROPERTY C_STANDARD 99)$ 

在Ubuntu上我可以成功地建立它:

$ git clone http://github.com/montao/openshell 
Cloning into 'openshell'... 
remote: Counting objects: 1439, done. 
remote: Compressing objects: 100% (184/184), done. 
remote: Total 1439 (delta 124), reused 0 (delta 0), pack-reused 1255 
Receiving objects: 100% (1439/1439), 405.08 KiB | 117.00 KiB/s, done. 
Resolving deltas: 100% (973/973), done. 
Checking connectivity... done. 
[email protected]:~/montao/test$ cd openshell/ 
[email protected]:~/montao/test/openshell$ mkdir build 
[email protected]:~/montao/test/openshell$ cd build/ 
[email protected]:~/montao/test/openshell/build$ cmake .. 
-- The C compiler identification is GNU 5.3.1 
-- The CXX compiler identification is GNU 5.3.1 
-- Check for working C compiler: /usr/bin/cc 
-- Check for working C compiler: /usr/bin/cc -- works 
-- Detecting C compiler ABI info 
-- Detecting C compiler ABI info - done 
-- Detecting C compile features 
-- Detecting C compile features - done 
-- Check for working CXX compiler: /usr/bin/c++ 
-- Check for working CXX compiler: /usr/bin/c++ -- works 
-- Detecting CXX compiler ABI info 
-- Detecting CXX compiler ABI info - done 
-- Detecting CXX compile features 
-- Detecting CXX compile features - done 
-- Configuring done 
-- Generating done 
-- Build files have been written to: /home/dac/montao/test/openshell/build 
[email protected]:~/montao/test/openshell/build$ make 
Scanning dependencies of target shellparser 
[ 14%] Generating ../shellparser.c 
Parser statistics: 
    terminal symbols...................  9 
    non-terminal symbols...............  3 
    total symbols...................... 12 
    rules..............................  8 
    states............................. 14 
    conflicts..........................  0 
    action table entries............... 32 
    total table size (bytes)........... 100 
[ 14%] Built target shellparser 
Scanning dependencies of target shell 
[ 28%] Building C object CMakeFiles/shell.dir/main.c.o 
/home/dac/montao/test/openshell/main.c: In function ‘free_pipeline’: 
/home/dac/montao/test/openshell/main.c:337:6: note: the ABI of passing struct with a flexible array member has changed in GCC 4.4 
void free_pipeline(struct pipeline pipe) { 
    ^
[ 42%] Building C object CMakeFiles/shell.dir/shellparser.c.o 
[ 57%] Building C object CMakeFiles/shell.dir/errors.c.o 
[ 71%] Building C object CMakeFiles/shell.dir/util.c.o 
/home/dac/montao/test/openshell/util.c: In function ‘make_args’: 
/home/dac/montao/test/openshell/util.c:1100:52: warning: operation on ‘jc’ may be undefined [-Wsequence-point] 
      char *str = concat((char *) *retArgv[jc++], (char *) *retArgv[jc]); 
                ^
/home/dac/montao/test/openshell/util.c:1100:19: warning: unused variable ‘str’ [-Wunused-variable] 
      char *str = concat((char *) *retArgv[jc++], (char *) *retArgv[jc]); 
       ^
[ 85%] Linking C executable shell 
[100%] Built target shell 

不管我做什么,错误的是那里当我在OpenBSD编译。我尝试了一切。

+1

显然,至少知道一个或两个在openBSD上编译器失败的行实际上是有帮助 –

+0

@MarcusMüller我终于可以编译它,如果我使用cmake柠檬然后制作。根据我的调用方式,柠檬会从'shellparser.y'生成不同的'shellparser.c'。我不确定细节,但至少我现在可以建立这个项目:-) – Montao

+1

如果你不添加答案,你并不真正帮助任何人(你可以自我回答问题,非常感谢在SO!)并解释你做了什么,并且实际显示不同的文件!除此之外,你的问题对未来的读者毫无价值:( –

回答

4

我还没有使用过OpenBSD,但是这可能是由2007年7月18日发布的“古老的”GCC 4.2.1引起的。在Ubuntu上它使用更新的GCC编译。

事实上,如果你检查的project you want to build

依赖关系的依赖关系:editline,ncurses的,C99

和C99支持gcc

C99基本上完全支持作为海湾合作委员会4.5(使用-std = c99 -pedantic-errors; -fextended-identifiers也需要在GCC 5之前启用扩展标识符)

+1

有趣的铅!我想,考虑到OP得到的错误,我认为这可能是他的语法分析器生成器不能按预期工作,这就是为什么我要求生成.c文件; .y文件不足以告知。 –

+0

无论我做什么,我都会收到错误信息,我尝试了所有内容。 – Montao

+0

@Montao您应该将'-pedantic'修改为'-pedantic-errors'修复错误。可能你必须在main.c中添加'#include \t 'OpenBSD ifdef。 – mati865

1

我能在OpenBSD 5.9

gcc -std=c99 shellparser.c main.c util.c errors.c -ledit -ltermcap

编译这样如果我第一次产生对Linux的shellparser.c和复制文件到OpenBSD的,那么上面的工作,以构建OpenBSD系统。但是我仍然无法用OpenBSD的语法生成C语言,出现了一个编译错误。我可以在Ubuntu上重新创建编译错误,并且我仍然在寻找导致生成的C中的diff的原因,当我运行lemon shellparser.y