I's m trying to compile gtest and gmock on windows10 with MinGW and Cmake;
Tools:
cmake --version
cmake version 3.21.1
gcc -v
gcc version 8.1.0
mingw32-make.exe -v
GNU Make 4.2.1
Built for x86_64-w64-mingw32
Build command as followed:
(base) PS D:\WorkSpace\Codes\GTest_GMock\googletest-master\build> cmake .. -G "MinGW Makefiles" -DCMAKE_CXX_FLAGS=-std=gnu++11
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python: D:/ProgramData/Miniconda3/python.exe (found version "3.9.5") found components: Interpreter
-- Configuring done
-- Generating done
-- Build files have been written to: D:/WorkSpace/Codes/GTest_GMock/googletest-master/build
(base) PS D:\WorkSpace\Codes\GTest_GMock\googletest-master\build> mingw32-make.exe
[ 12%] Building CXX object googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj
系统找不到指定的路径。(cannot find path)
mingw32-make[2]: *** [googletest\CMakeFiles\gtest.dir\build.make:76: googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj] Error 1
mingw32-make[2]: *** Deleting file 'googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj'
mingw32-make[1]: *** [CMakeFiles\Makefile2:171: googletest/CMakeFiles/gtest.dir/all] Error 2
mingw32-make: *** [Makefile:145: all] Error 2
(base) PS D:\WorkSpace\Codes\GTest_GMock\googletest-master\build>
I'm trying to modernize a build system with CMake. When I try to compile the program with make I get this output
$ cmake -DCMAKE_TOOLCHAIN_FILE="../armgcc.cmake" .. && make
-- The C compiler identification is GNU 9.2.1
-- The CXX compiler identification is GNU 9.2.1
-- Check for working C compiler: /usr/bin/arm-none-eabi-gcc
-- Check for working C compiler: /usr/bin/arm-none-eabi-gcc -- 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/arm-none-eabi-g++
-- Check for working CXX compiler: /usr/bin/arm-none-eabi-g++ -- 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: ~/cmake_test/build
Scanning dependencies of target testproj
[ 50%] Building C object CMakeFiles/testproj.dir/main.c.obj
[100%] Linking C executable testproj
arm-none-eabi-gcc: fatal error: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/nosys.specs: attempt to rename spec 'link_gcc_c_sequence' to already defined spec 'nosys_link_gcc_c_sequence'
compilation terminated.
make[2]: *** [CMakeFiles/testproj.dir/build.make:84: testproj] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/testproj.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
With CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(testproj VERSION 0.1.0)
add_executable(testproj main.c)
and armgcc.cmake
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --specs=nosys.specs")
What are link_gcc_sequence and nosys_link_gcc_sequence, and how should I structure my CMakeLists to avoid renaming them?
I am a beginner in programming with C and I get this error code if i start a project on CLion:
C:\Program Files\JetBrains\CLion 2017.2.2\bin\cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\danie\CLionProjects\untitled2
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is unknown
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at CMakeLists.txt:2 (project):
The CMAKE_CXX_COMPILER:
g++.exe
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "C:/Users/danie/CLionProjects/untitled2/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "C:/Users/danie/CLionProjects/untitled2/cmake-build-debug/CMakeFiles/CMakeError.log".
[Finished]
What can I do to get it working?
Thank you for your help.
By default, CMake expects that project needs support for both C and C++. If your project needs only C, specify that in project() call:
project(<project-name> C)
My program used to compile fine with OpenBSD before I added the lemon parser. Now it compiles on Linux but on OpenBSD I get an error I don't understand.
$ 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
Why is is happening and what can I do about it? Did I forget to include a library? My cmake file is
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)$
On Ubuntu I can build it successfully:
$ 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
No matter what I do, the error is there when I compile with OpenBSD. I tried everything.
I haven't used OpenBSD but this could be caused by an "ancient" GCC 4.2.1 which was released 18 July 2007. On Ubuntu it's compiled with more recent GCC.
In fact if you check dependencies of project you want to build
Dependencies: editline, ncurses, C99
And C99 support in gcc
C99 is substantially completely supported as of GCC 4.5 (with -std=c99 -pedantic-errors used; -fextended-identifiers also needed to enable extended identifiers before GCC 5)
I can compile it like this with OpenBSD 5.9
gcc -std=c99 shellparser.c main.c util.c errors.c -ledit -ltermcap
IF I first generate the shellparser.c with Linux and copy the file to OpenBSD, then the above works to build for OpenBSD. But I still can't generate the C from the grammar with OpenBSD, there comes a compilation error. I can recreate the compilation error on Ubuntu and I'm still looking for what causes the diff in the generated C when I run lemon shellparser.y
I've been tring to build portmidi on OSX 10.8.2
http://sourceforge.net/apps/trac/portmedia/wiki/Installing%20portmidi%20on%20Mac
Anyway, the README tells me to first use the command:
make -f pm_mac/Makefile.osx
but bash returns the following error message:
[~/Desktop/portmedia/portmidi]
DanMoore -> make -f pm_mac/Makefile.osx
rm -f CMakeCache.txt
mkdir -p Release
cd Release; cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
-- The C compiler identification is GNU 4.2.1
-- The CXX compiler identification is Clang 4.0.0
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- 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 - failed
-- SYSROOT: /Developer/SDKs/MacOSX10.5.sdk
-- DEFAULT_DEBUG_FLAGS not nil: -g
-- SYSROOT: /Developer/SDKs/MacOSX10.5.sdk
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/DanMoore/Desktop/portmedia/portmidi/Release
cd Release; make
Scanning dependencies of target pmjni
[ 3%] Building C object pm_common/CMakeFiles/pmjni.dir/__/pm_mac/pmmacosxcm.c.o
llvm-gcc-4.2: error trying to exec '/usr/bin/../llvm-gcc-4.2/bin/powerpc-apple-darwin11-llvm-gcc-4.2': execvp: No such file or directory
lipo: can't figure out the architecture type of: /var/folders/y4/p_kjk8692z73xy4nhwx6h_100000gn/T//cc73yejt.out
make[3]: *** [pm_common/CMakeFiles/pmjni.dir/__/pm_mac/pmmacosxcm.c.o] Error 255
make[2]: *** [pm_common/CMakeFiles/pmjni.dir/all] Error 2
make[1]: *** [all] Error 2
make: *** [all] Error 2
I wasn't expecting an easy build, but these errors look foreign to me.
Can anyone explain whats going on??
I'm trying to render a library file for simple C programs. (.a or .la)
Thanks in advance to anyone who takes a look!!