سؤال

I have an C project on github, I`m trying to build the code in Travis-CI but I get this error:

Using worker: worker-linux-9-2.bb.travis-ci.org:travis-linux-2
$ export CC=gcc
git.1
$ git clone --depth=50 --branch=someDevs git://github.com/luizfilipe/ffb-cglib.git     luizfilipe/ffb-cglib
Cloning into 'luizfilipe/ffb-cglib'...
remote: Counting objects: 114, done.
remote: Compressing objects: 100% (93/93), done.
remote: Total 114 (delta 27), reused 80 (delta 12)
Receiving objects: 100% (114/114), 2.53 MiB | 0 bytes/s, done.
Resolving deltas: 100% (27/27), done.
Checking connectivity... done.
$ cd luizfilipe/ffb-cglib
git.3
$ git checkout -qf f76cd622418a75003d1aa6326c38039c1f556ee8
$ gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ make
gcc -c -pendantic examples/environment/main.c -I/usr/bin/Mesa-5.0/include -g
make: gcc: Command not found
make: *** [main.o] Error 127
The command "make" exited with 2.
Done. Your build exited with 1.

Reading the error i notice that gcc wasn't found, but the .travis.yml is cofigured like following:

language: c
compiler:
   - gcc
script: make

Makefile is configured like follows:

# Variables
MESA = /usr/bin/Mesa-5.0
PATH = examples/environment/main
EXAMPLE_ENVIRONMENT = examples/environment/main.c
INCPATH = -I$(MESA)/include
LIBPATH = -L$(MESA)/lib
LIBS        = -lglut -lGLU -lGL -lm
CFLAGS  = $(INCPATH) -g
LFLAGS  = $(LIBPATH) $(LIBS)

# Main targets
all: main.o
    $(CC) -o $(PATH) main.o $(LFLAGS)

# Source targets
main.o: $(EXAMPLE_ENVIRONMENT)
    $(CC) -c -pendantic $(EXAMPLE_ENVIRONMENT) $(CFLAGS)

Any thoughts?

UPDATE: I just cut off the clang and put the Makefile more agnostic and I still getting the same issue.

هل كانت مفيدة؟

المحلول

The problem is that you hard code your compiler then ask travis to build against two compilers. This means that travis will try to build your code with gcc then again with clang. You have two options remove clang as a compiler from your .travis.yml or change your makefile to be compiler agnostic. To change you makefile just replace all instances of gcc with $(CC)

Also $PATH contains the locations to look in for executables. If you overwrite it make can't find anything. so you need to rename $PATH to something like example_path eg

# Variables
MESA = /usr/bin/Mesa-5.0
example_path = examples/environment/
EXAMPLE_ENVIRONMENT = examples/environment/main.c
INCPATH = -I$(MESA)/include
LIBPATH = -L$(MESA)/lib
LIBS        = -lglut -lGLU -lGL -lm
CFLAGS  = $(INCPATH) -g
LFLAGS  = $(LIBPATH) $(LIBS)

# Main targets
all: main.o
    $(CC) -o $(example_path)/main.o $(LFLAGS)

# Source targets
main.o: $(EXAMPLE_ENVIRONMENT)
    $(CC) -c -pendantic $(EXAMPLE_ENVIRONMENT) $(CFLAGS)

You will also need to add a before_install section to your .travis.yml file to install Mesa as the travis images are very minimal.

نصائح أخرى

The problem is that you hard code your compiler then ask travis to build against two compilers.

As an example of a project who did just that, and changed its Travis CI settings to resolve that issue, see Git 2.21 (Feb. 2019), where the travis CI scripts have been corrected to build Git with the compiler(s) of our choice.

See commit 2c8921d, commit 2000ac9, commit bbf24ad, commit ff0eec9 (17 Jan 2019) by SZEDER Gábor (szeder).
(Merged by Junio C Hamano -- gitster -- in commit 51b9966, 07 Feb 2019)

travis-ci: build with the right compiler

Our 'Makefile' hardcodes the compiler to build Git as 'CC = cc'.
This CC variable can be overridden from the command line, i.e. 'make CC=gcc-X.Y' will build with that particular GCC version, but not from the environment, i.e. 'CC=gcc-X.Y make' will still build with whatever 'cc' happens to be on the platform.

Our build jobs on Travis CI are badly affected by this.

In the build matrix we have dedicated build jobs to build Git with GCC and Clang both on Linux and macOS from the very beginning (522354d (Add Travis CI support, 2015-11-27, Git v2.7.0-rc0)).
Alas, this never really worked as supposed to, because Travis CI specifies the compiler for those build jobs as 'export CC=gcc' and 'export CC=clang' (which works fine for projects built with './configure && make').
Consequently, our 'linux-clang' build job has always used GCC, because that's where 'cc' points at in Travis CI's Linux images, while the 'osx-gcc' build job has always used Clang.
Furthermore, 37fa4b3 (travis-ci: run gcc-8 on linux-gcc jobs, 2018-05-19, Git v2.18.0-rc0) added an 'export CC=gcc-8' in an attempt to build with a more modern compiler, but to no avail.

Set MAKEFLAGS with CC based on the $CC environment variable, so 'make' will run the "right" compiler.
The Xcode 10.1 macOS image on Travis CI already contains the gcc@8 package from Homebrew, but we have to 'brew link' it first to be able to use it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top