I am using ninja to build a program for the first time. I run the command ninja from the cmd but get the error:
ninja: error: build.ninja:3: lexing error
What is the issue?
Here is my build.ninja file:
rule compile
command = gcc -Wall -c $in -o $out
rule link
command = gcc $in -o $out
build hello.o: compile main.c
build hello: link hello.o `
and here is main.c:
int main() {
printf("Hello world\n");
return 0;
}
Related
I am new to Frama-C. I specifically need to use e-acsl plugin for verification purposes. I used first.i file as
int main(void) {
int x = 0;
/∗# assert x == 0; ∗/
/∗# assert x == 1; ∗/
return 0;
}
Created monitored_first.c file from first.i file using the following command.
$ frama-c -e-acsl first.i -then-last -print -ocode monitored_first.c
The main function inside the monitored_first.c looks like the one below.
int main(void)
{
int __retres;
__e_acsl_memory_init((int *)0,(char ***)0,8UL);
int x = 0;
__retres = 0;
__e_acsl_memory_clean();
return __retres;
}
It is not adding e_acsl assertion for x==1.
I tried it using the "e-acsl-gcc.sh" script , which generated the monitored_first.i file. But the main function inside monitored_first.i is same as that in monitored_first.c.
$ e-acsl-gcc.sh -c -omonitored_first.i first.i
The above command generated two executable, "a.out.e-acsl" and "a.out". It also generates some warnings when run in ubuntu 22.04 as follows:
/home/amrutha/.opam/4.11.1/bin/frama-c -remove-unused-specified-functions -machdep gcc_x86_64 '-cpp-extra-args= -std=c99 -D_DEFAULT_SOURCE -D__NO_CTYPE -D__FC_MACHDEP_X86_64 ' -no-frama-c-stdlib first.i -e-acsl -e-acsl-share=/home/amrutha/.opam/4.11.1/bin/../share/frama-c/e-acsl -then-last -print -ocode monitored_first.i
[kernel] Parsing first.i (no preprocessing)
[e-acsl] beginning translation.
[kernel] Parsing FRAMAC_SHARE/e-acsl/e_acsl.h (with preprocessing)
/tmp/ppannot15ad34.c:362: warning: "__STDC_IEC_60559_BFP__" redefined
362 | #define __STDC_IEC_60559_BFP__ 201404L
|
In file included from <command-line>:
/usr/include/stdc-predef.h:39: note: this is the location of the previous definition
39 | # define __STDC_IEC_60559_BFP__ 201404L
|
/tmp/ppannot15ad34.c:363: warning: "__STDC_IEC_60559_COMPLEX__" redefined
363 | #define __STDC_IEC_60559_COMPLEX__ 201404L
|
In file included from <command-line>:
/usr/include/stdc-predef.h:49: note: this is the location of the previous definition
49 | # define __STDC_IEC_60559_COMPLEX__ 201404L
|
[e-acsl] translation done in project "e-acsl".
+ gcc -std=c99 -m64 -g -O2 -fno-builtin -fno-merge-constants -Wall -Wno-long-long -Wno-attributes -Wno-nonnull -Wno-undef -Wno-unused -Wno-unused-function -Wno-unused-result -Wno-unused-value -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable -Wno-implicit-function-declaration -Wno-empty-body first.i -o a.out
+ gcc -DE_ACSL_SEGMENT_MMODEL -std=c99 -m64 -g -O2 -fno-builtin -fno-merge-constants -Wall -Wno-long-long -Wno-attributes -Wno-nonnull -Wno-undef -Wno-unused -Wno-unused-function -Wno-unused-result -Wno-unused-value -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable -Wno-implicit-function-declaration -Wno-empty-body -I/home/amrutha/.opam/4.11.1/bin/../share/frama-c/e-acsl -o a.out.e-acsl monitored_first.i /home/amrutha/.opam/4.11.1/bin/../share/frama-c/e-acsl/e_acsl_rtl.c /home/amrutha/.opam/4.11.1/bin/../lib/frama-c/e-acsl/libeacsl-dlmalloc.a -lgmp -lm
In ubuntu 20.04 there is no any warning, only the end part is getting displayed. When run ./a.out.e-acsl , it simply run the code without any message, which is not supposed. The expected output should look like this:
$ ./a.out.e-acsl
first.i: In function 'main'
first.i:4: Error: Assertion failed:
The failing predicate is:
x == 1.
Aborted (core dumped)
$ echo $?
134
I tried it in ubuntu 22.04 with opam version 2.1.2 and Fragma-C 25.0
and ubuntu 20.04 with opam version 2.0.5 and Fragma-C 25.0
The same issue has been posted to Frama-C's public bug tracking and it seems the cause might have been the non-ASCII asterisk characters used in the ACSL annotations: ∗ instead of *.
I still don't understand how the comments could parse at all (my compiler gives a syntax error), but the user seems to indicate that replacing them solved the problem.
In any case, in similar situations one can either use the Frama-C GUI to open the parsed file and check if Frama-C recognizes the ACSL annotations (they should show up in the CIL normalized code), or try other analyses, e.g. running frama-c -eva and checking that it detects the annotations.
Suppose I have the following c source code, in dexp_test.c:
#include <stdio.h>
double dexp(double x, double scale, int log);
int main() {
double x;
x = dexp(1 , 2, 0);
printf("Value: %f\n", x);
return 0;
}
where dexp is defined in R's source code (https://github.com/wch/r-source/blob/trunk/src/nmath/dexp.c). I would like to compile this to a standalone executable. I have R 4.0 installed on my system. I have the following gcc lines:
gcc r-source/src/nmath/dexp.c -I/Library/Frameworks/R.framework/Versions/4.0/Resources/include -c -o a.o
gcc dexp_test.c -c -o b.o
These lines run just fine on my system and I am left with new files a.o and b.o without errors.
When I run this line to get an executable:
gcc -o test_exp a.o b.o
...I get these errors:
Undefined symbols for architecture x86_64:
"_R_NaN", referenced from:
_Rf_dexp in a.o
"_R_NegInf", referenced from:
_Rf_dexp in a.o
"_dexp", referenced from:
_main in b.o
(maybe you meant: _Rf_dexp)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I'm definitely missing something conceptually here; how do I get this to compile? If it helps, I'm on OSX 15.6, and the output of gcc -v is
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
You should mention the operating system you are using.
You need to include the appropriate headers. And tell the linker where and which libraries you want to use.
So your source should be
#include <stdio.h>
#include <R.h>
#include <Rmath.h>
int main() {
double x;
x = dexp(1 , 2, 0);
printf("Value: %f\n", x);
return 0;
}
And on the command line you should use the following
gcc -I/Library/Frameworks/R.framework/Versions/4.0/Resources/include -L/Library/Frameworks/R.framework/Versions/4.0/Resources/lib -lR -o test_exp trydexp.c
Here's a compilation problem.
The project works on Linux and OS X and must be ported to Windows. It uses RInside and Rcpp librairies.
To do so, I installed R, Cygwin and RTools and compiled the R librairies. It worked fine.
Now the problem:
The QMake step happens with no error, but the building exits with an error. I get this :
error: [1]: No such file or directory
error: Rcpp:::CxxFlags(): Invalid argument
error: [1]: No such file or directory
error: RInside:::CxxFlags(): Invalid argument
Long version:
17:18:36: Débute : "C:\Qt\Qt5.7.0\Tools\mingw530_32\bin\mingw32-make.exe"
C:/Qt/Qt5.7.0/5.7/mingw53_32/bin/qmake.exe -spec win32-g++ CONFIG+=debug CONFIG+=qml_debug -o Makefile ../IHM/Rpp-IHM.pro
C:/Qt/Qt5.7.0/Tools/mingw530_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Users/Henri/Desktop/rpp/src/build-Rpp-IHM-Desktop_Qt_5_7_0_MinGW_32bit-Debug'
g++ -c -pipe -fno-keep-inline-dllexport -Wno-unused-parameter -IC:/Progz/R-3.3.2/include -IC:/Progz/R-3.3.2/include/x64 [1] "Rcpp:::CxxFlags()" [1] "RInside:::CxxFlags()" -g -std=gnu++11 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_SVG_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../IHM -I. -I../computer/RppUtils -I../computer/RppEngine -IC:/Qt/Qt5.7.0/5.7/mingw53_32/include -IC:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtSvg -IC:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtWidgets -IC:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtGui -IC:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtANGLE -IC:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtCore -Idebug -IC:/Qt/Qt5.7.0/5.7/mingw53_32/mkspecs/win32-g++ -o debug/WrapperRppR.o ../IHM/WrapperRppR.cpp
g++.exe: error: [1]: No such file or directory
g++.exe: error: Rcpp:::CxxFlags(): Invalid argument
g++.exe: error: [1]: No such file or directory
g++.exe: error: RInside:::CxxFlags(): Invalid argument
Makefile.Debug:2914: recipe for target 'debug/WrapperRppR.o' failed
mingw32-make[1]: *** [debug/WrapperRppR.o] Error 1
mingw32-make[1]: Leaving directory 'C:/Users/Henri/Desktop/rpp/src/build-Rpp-IHM-Desktop_Qt_5_7_0_MinGW_32bit-Debug'
Makefile:34: recipe for target 'debug' failed
mingw32-make: *** [debug] Error 2
17:18:40: Le processus "C:\Qt\Qt5.7.0\Tools\mingw530_32\bin\mingw32-make.exe" s'est terminé avec le code 2.
Erreur lors de la compilation/déploiement du projet Rpp-IHM (kit : Desktop Qt 5.7.0 MinGW 32bit)
When executing step "Make"
In fact, it seems that it doesn't find RInside.h, in spite of the fact that the R_HOM variable is set to the directory of R (here : C:/Progz/R-3.3.2/).
Here's a part of the .pro file:
QT += core gui svg
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Rpp-IHM
TEMPLATE = app
CONFIG += c++11
CONFIG += -v
## comment this out if you need a different version of R,
## and set set R_HOME accordingly as an environment variable
## R_HOM = $$system($$R_HOME)
win32 {
#A specifier
R_HOM = "C:/Progz/R-3.3.2/"
}
unix:!macx {
# WORKING
R_HOM = "/usr/lib/R/"
}
macx {
# WORKING
R_HOM = "/Library/Frameworks/R.framework/Resources/"
}
## include headers and libraries for R
RCPPFLAGS = $$system($$R_HOM/bin/R CMD config --cppflags)
RLDFLAGS = $$system($$R_HOM/bin/R CMD config --ldflags)
RBLAS = $$system($$R_HOM/bin/R CMD config BLAS_LIBS)
RLAPACK = $$system($$R_HOM/bin/R CMD config LAPACK_LIBS)
## if you need to set an rpath to R itself, also uncomment
RRPATH = -Wl,-rpath,R_HOME/lib
## include headers and libraries for Rcpp interface classes
RCPPINCL = $$system($$R_HOM/bin/Rscript -e \'Rcpp:::CxxFlags\(\)\')
RCPPLIBS = $$system($$R_HOM/bin/Rscript -e \'Rcpp:::LdFlags\(\)\')
## for some reason when building with Qt we get this each time
## so we turn unused parameter warnings off
RCPPWARNING = -Wno-unused-parameter
## include headers and libraries for RInside embedding classes
RINSIDEINCL = $$system($$R_HOM/bin/Rscript -e \'RInside:::CxxFlags\(\)\')
RINSIDELIBS = $$system($$R_HOM/bin/Rscript -e \'RInside:::LdFlags\(\)\')
INCLUDEPATH = ../computer/RppUtils
INCLUDEPATH += ../computer/RppEngine
## compiler etc settings used in default make rules
QMAKE_CXXFLAGS += $$RCPPWARNING $$RCPPFLAGS $$RCPPINCL $$RINSIDEINCL
QMAKE_LFLAGS += $$RLDFLAGS $$RBLAS $$RLAPACK $$RCPPLIBS $$RINSIDELIBS
QMAKE_CXXFLAGS_WARN_OFF += -Wunused-parameter
What did I miss?
Error in invoking target 'install' of makefile '/u01/app/oracle/product/11.2.0/dbhome_1/ctx/lib/ins_ctx.mk'. See '/u01/app/oraInventory/logs/installActions2015-02-28_02-22-27AM.log' for details.
I get the above error when I run the installer of Oracle 11g release 2
The log is as follows
INFO: gcc -o ctxhx -m64 -L/u01/app/oracle/product/11.2.0/dbhome_1/ctx/lib/ -L/u01/app/oracle/product/11.2.0/dbhome_1/lib/ -L/u01/app/oracle/product/11.2.0/dbhome_1/lib/stubs/ /u01/app/oracle/product/11.2.0/dbhome_1/ctx/lib/ctxhx.o -L/u01/app/oracle/product/11.2.0/dbhome_1/ctx/lib/ -lm -ldl -lsc_ca -lsc_fa -lsc_ex -lsc_da -lsc_ut -lsc_ch -lsc_fi -lctxhx -lc -Wl,-rpath,/u01/app/oracle/product/11.2.0/dbhome_1/ctx/lib -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -lxml11 -lcore11 -lunls11 -ls
INFO: nls11 -lnls11 -lcore11 -lnls11
INFO: /usr/bin/ld: /u01/app/oracle/product/11.2.0/dbhome_1/lib//libcore11.a(sslss.o): undefined reference to symbol 'pthread_sigmask##GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
INFO: collect2: error: ld returned 1 exit status
INFO: make: *** [ctxhx] Error 1
INFO: End output from spawned process.
INFO: ----------------------------------
INFO: Exception thrown from action: make
Exception Name: MakefileException
Exception String: Error in invoking target 'install' of makefile '/u01/app/oracle/product/11.2.0/dbhome_1/ctx/lib/ins_ctx.mk'. See '/u01/app/oraInventory/logs/installActions2015-02-28_02-22-27AM.log' for details.
Please help me fix this... Thanks in advance.
Try to link with g++ instead of gcc.
cd /bin
mv gcc gcc.save
ln -s g++ gcc
and run the installer again.
Create the following script the run it a root during install the click retry
# Fix ctx/lib/ins_ctx.mk
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
cat << __EOF__ > /tmp/memcpy_wrap.c
#include <stddef.h>
#include <string.h>
asm (".symver wrap_memcpy, memcpy#GLIBC_2.14");
void *wrap_memcpy(void *dest, const void *src, size_t n) {
return memcpy(dest, src, n);
}
__EOF__
if [[ -e "${ORACLE_HOME}/ctx/lib/ins_ctx.mk" ]]; then
sed -i -e 's/\$(INSO_LINK)/\$(INSO_LINK) -Wl,--wrap=memcpy_wrap \$(ORACLE_HOME)\/ctx\/lib\/memcpy_wrap.o/g' ${ORACLE_HOME}/ctx/lib/ins_ctx.mk
gcc -c /tmp/memcpy_wrap.c -o ${ORACLE_HOME}/ctx/lib/memcpy_wrap.o && rm /tmp/memcpy_wrap.c
fi
If I run this script: (Note: edited to reflect answer 1)
#!/usr/bin/env zsh
setopt shwordsplit
if [[ -f $1 ]]
then
echo "will compile $1"
else
echo "ERROR: $1 NOT found"
exit 1
fi
gcc_options=" -c -std=c99 -Wall -Wextra "
echo "gcc_options: ${gcc_options}"
gcc " ${=gcc_options} " " ${=1} "
if [[ $? -eq 0 ]]
then
echo "gcc compile worked"
else
echo "error in gcc compile"
fi
gcc "${=gcc_options}" "${=1}"
if [[ $? -eq 0 ]]
then
echo "gcc compile worked"
else
echo "error in gcc compile"
fi
Both compiles fail.
Output is:
will compile my_file.c
gcc_options: -c -std=c99 -Wall -Wextra
gcc: error: : No such file or directory
gcc: error: : No such file or directory
gcc: error: my_file.c : No such file or directory
gcc: fatal error: no input files compilation terminated.
error in gcc compile
gcc: error: : No such file or directory
gcc: error: : No such file or directory
error in gcc compile
First change:
gcc " $gcc_options $1"
To:
gcc "$gcc_options" "$1"
If some of these variables contain multiple words, you may need to turn on shwordsplit (see here), which can also be done on a per variable basis (${=VAR}).
gcc "${=gcc_options}" "${=1}"
Update
I made a mistake, you definitely don't want quotes on $gcc_options, so it should probably be ${=gcc_options}. If you need to quote $1 depends if $1 contains spaces. So this should do:
gcc ${=gcc_options} $1