Почему я не могу скомпилировать с OpenBSD?

Моя программа отлично компилировалась с OpenBSD до того, как я добавил анализатор лимона. Теперь он компилируется в Linux, но в 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.
dac@dac-Latitude-E7450:~/montao/test$ cd openshell/
dac@dac-Latitude-E7450:~/montao/test/openshell$ mkdir build
dac@dac-Latitude-E7450:~/montao/test/openshell$ cd build/
dac@dac-Latitude-E7450:~/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
dac@dac-Latitude-E7450:~/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 возникает ошибка. Я пробовал все.


person Montao    schedule 14.05.2016    source источник
comment
очевидно, что знание хотя бы одной или двух строк, где ваш компилятор в openBSD дает сбой, было бы действительно полезно.   -  person Marcus Müller    schedule 14.05.2016
comment
@MarcusMüller Наконец-то я смог его скомпилировать, если воспользуюсь лимоном из cmake, а затем make. Lemon будет генерировать разные shellparser.c из shellparser.y в зависимости от того, как я его вызываю. Я не уверен в деталях, но, по крайней мере, теперь я могу построить проект :-)   -  person Montao    schedule 15.05.2016
comment
На самом деле вы никому не поможете, кроме себя, если не добавите ответ (вы можете самостоятельно отвечать на вопросы, это очень ценится на SO!) И объясните, что вы сделали, и на самом деле покажете файлы, которые отличаются! В остальном ваш вопрос не представляет никакой ценности для будущих читателей :(   -  person Marcus Müller    schedule 15.05.2016
comment
@MarcusMüller все еще ищет, почему сгенерировать код в Ubuntu, а затем запустить его в OpenBSD. Но это работает. На самом деле я сразу обновил инструкцию по сборке (github.com/montao/openshell)   -  person Niklas R.    schedule 17.05.2016


Ответы (2)


Я не использовал OpenBSD, но это может быть вызвано «древним» GCC 4.2.1, выпущенным 18 июля 2007 года. В Ubuntu он скомпилирован с более поздним GCC.

На самом деле, если вы проверите зависимости проекта, который хотите построить

Зависимости: editline, ncurses, C99

Поддержка C99 в gcc.

C99 практически полностью поддерживается, начиная с GCC 4.5 (с использованием -std=c99 -pedantic-errors; -fextended-identifiers также необходимы для включения расширенных идентификаторов до GCC 5)

person mati865    schedule 14.05.2016
comment
Интересный ведущий! Я думаю, учитывая ошибки, которые получает OP, я думаю, что его генератор синтаксического анализа может работать не так, как ожидалось. Вот почему я прошу сгенерированные файлы .c; файла .y недостаточно, чтобы сказать. - person Marcus Müller; 14.05.2016
comment
Что бы я ни делал, я получаю ошибку. Я пробовал все. - person Montao; 14.05.2016
comment
@Montao, вы должны изменить -pedantic на -pedantic-errors, чтобы исправить ошибки. Вероятно, вам придется добавить #include <readline/history.h> в OpenBSD ifdef в main.c. - person mati865; 14.05.2016
comment
Ошибка также возникает, когда я пробую этот пример: "title="используйте лимонный парсерлалр, создайте калькулятор, как получить параметр из выражений"> stackoverflow.com/questions/34918631/, поэтому у нас есть минимальный способ его воспроизведения. - person Montao; 14.05.2016

Я могу скомпилировать это с помощью OpenBSD 5.9.

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

ЕСЛИ я сначала сгенерирую shellparser.c с помощью Linux и скопирую файл в OpenBSD, то описанное выше будет работать для сборки для OpenBSD. Но я все еще не могу сгенерировать C из грамматики с OpenBSD, возникает ошибка компиляции. Я могу воссоздать ошибку компиляции в Ubuntu, и я все еще ищу, что вызывает разницу в сгенерированном C, когда я запускаю lemon shellparser.y

person Niklas R.    schedule 17.05.2016