I heard that if you run Nim to generate C-code:
nim c -d: release try1.nim
Then the further generated C code can be slipped into any compiler on any operating system.
In the nimcache folder, the following is generated:
# mtry1.nim.c
stdlib_io.nim.c
stdlib_system.nim.c
try1.json
What to do next with this for compilation?
You might want to try and run nim c -d:release --genScript try1.nim. This will generate a compile_try1 script in the nimcache folder that should be able to compile the C sources generated by Nim.
nim c --cpu:mips --os:linux --compileOnly --genScript [name_project].nim
Copy everything from nimcache DIR to ur OS (which have ur toolchain (ecc, crosstoolng and etc.))
Edit script compile_[name_project].sh with necessary gcc lib
for example, mipsel-linux-gnu-gcc-9 script (If u haven't it try on Ubuntu sudo apt install gcc-9-multilib-mipsel-linux-gnu):
mipsel-linux-gnu-gcc-9 -c -w -fmax-errors=3 -IC:\nim\lib -IC:\nim\nim_practice -o stdlib_io.nim.c.o stdlib_io.nim.c
mipsel-linux-gnu-gcc-9 -c -w -fmax-errors=3 -IC:\nim\lib -IC:\nim\nim_practice -o stdlib_system.nim.c.o stdlib_system.nim.c
mipsel-linux-gnu-gcc-9 -c -w -fmax-errors=3 -IC:\nim\lib -IC:\nim\nim_practice -o #m[name_projet].nim.c.o #m[name_projet].nim.c
mipsel-linux-gnu-gcc-9 -static -o3 -Wall -fPIC -o [name_projet] stdlib_io.nim.c.o stdlib_system.nim.c.o #m[name_projet].nim.c.o -ldl
Related
My C program uses string.h.. Initially I was not able to compile it. But then I used
$ gcc filename.c -E
Then it complied but I am not able to run it with both
./a.out
./filename
The -E option to gcc invokes only the preprocessor. If you want to compile you need to do this:
gcc -g -Wall -Wextra -o filename filename.c
The -o option specifies the name of the executable to create, the -W options enable the common compiler warnings, and -g includes debugging symbols so you can use tools such as gdb to step through the code line by line.
I am new to Ubuntu and new to C programming. Now I am watching cs50 videos to understand better about C and CS all together.
I tried to install this by using these guidelines:
Debian, Ubuntu
First become root, as with:
sudo su -
Then install the CS50 Library as follows:
apt-get install gcc
wget http://mirror.cs50.net/library50/c/library50-c-5.zip
unzip library50-c-5.zip
rm -f library50-c-5.zip
cd library50-c-5
gcc -c -ggdb -std=c99 cs50.c -o cs50.o
ar rcs libcs50.a cs50.o
chmod 0644 cs50.h libcs50.a
mkdir -p /usr/local/include
chmod 0755 /usr/local/include
mv -f cs50.h /usr/local/include
mkdir -p /usr/local/lib
chmod 0755 /usr/local/lib
mv -f libcs50.a /usr/local/lib
cd ..
rm -rf library50-c-5
I used it, and I think everything went as planned, but as soon as I try to run gcc demo.c I get a fatal error message:
adder.c:2:18: fatal error: cs50.h: No such file or directory
#include <cs50.h>
So as it seems that somewhere something went wrong and I don't really know how to fix it. Could anyone guide me a little bit how to fix it or how reinstall everything that C automatically would include that library?
check in the /usr/local/include directory for the cs50.h file
If it was not there, then one or more of the shell commands failed (or was skipped).
have you tried running gcc to compile/link the demo.c file via:
gcc -c -Wall -Wextra -pedantic -Wconversion -std=gnu99 demo.c -o demo.o -I/usr/local/include
gcc demo.o -o demo -L/usr/local/lib -lcs50
If your not sure what the above two lines do, just ask.
<CS50.h> exist on the CS50 IDE only. The functions it contains are string as a type def and the get functions.
If you use char * instead of string type
and
scanf() instead of get_(type)
You do not need it.
If you do need it I would just use the IDE in the course. It's free and halfway through the course they take the training wheels off.
Use -lcs50 in the end. Also specify the file where you want the machine code output using the -o parameter.
Run this to compile the program: gcc demo.c -o demo -lcs50
Run this to execute the program: ./demo
I'm trying to compile code from a backtrace project https://code.google.com/p/backtrace-mingw/ which is written for MinGW, but using MinGW-w64.
My old install and fresh install of MinGW-w64 produce the same problem. Path is set in path variables, and also in command prompt:
C:\mingw-w64\i686-4.9.2-win32-sjlj-rt_v3-rev1\mingw32\bin
and C:\mingw-w64\i686-4.9.2-win32-sjlj-rt_v3-rev1\mingw32 although this one isn't needed.
This is the makefile of that project:
.PHONY: all clean
all : backtrace.dll test.exe
backtrace.dll : backtrace.c
gcc -O2 -shared -Wall -o $# $^ -lbfd -lintl -liberty -limagehlp
test.exe : test.c
gcc -g -Wall -o $# $^
clean :
-del -f backtrace.dll test.exe
When compiling I get the warning:
backtrace.c:23:17: fatal error: bfd.h: No such file or directory #include < bfd.h>`
Which is weird because that file exists in ../mingw32/include folder.
If I add this when compilind the dll: -IC:\mingw-w64\i686-4.9.2-win32-sjlj-rt_v3-rev1\mingw32\include it continues but stops at the directive: #error config.h must be included before this header and config.h is missing in MinGW-w64
Any ideas?
That path is definetely missing from gcc include paths in mingw. I don't know why. You have to add it yourself in any way you like: cmake recipe, autoconf recipe, CFLAGS, CPATH, gcc specs.
And, as far as I remember, it uses only HAVE_STRINGIZE macro from config.h and it is used only to define CONCAT4 macro, that's not used anywhere in bfd.h. So, it's safe to cheat a little and put
#define PACKAGE package
before including bfd.h
add this to the end of the compile statement:
-I./mingw32/include
so the whole compile statement would be:
gcc -g -Wall -o $# $^ -I./mingw32/include
so the compiler knows where to find the include files
I am using Linux mint 16. I had a code that I change it a bit.
I use two following commands in terminal in order to run the code. The problem is that it does not give me any error but the changes are not applied, which means it runs the previous version of code.
gcc -std=c99 -c Code.c -o Code.o
./Code
gcc -std=c99 -c Code.c -o Code.o will put the compiled object file in Code.o, not ./Code as you expect it to be..
Also, -c tells do not run the linker. So effectively you end up with an object file which cannot be run.
gcc -std=c99 Code.c -o Code will produce what you need.
For a complete list of gcc flags either use man gcc or see http://linux.die.net/man/1/gcc
Try
gcc -std=c99 -c Code.c -o Code
./Code
I need to compile an old application whose tarball only contains *.c and *h, ie. no Makefile. The root directory contains the application, and a sub-directory contains a library the application needs.
My make/Makefile knowledge isn't great, and I was wondering what the easiest way would be to compile this application + library.
Thank you.
Edit: Using this script...
# cat compile.bash
#!/bin/bash
cd mylib
for cfile in *.c; do
ofile=$(echo "$cfile" | sed 's#.c$#.so#')
gcc -shared -c "$cfile" -o "$ofile"
done
cd ..
gcc *.c -I mylib -L mylib -mylib -o myapp
... I notice that each *.c file in mylib/ is compiled into a *.so file instead of compiling each into an object file and building a single .so file, and I get tons of warnings and errors, eg.
unzip.c: In function âunzipâ:
unzip.c:991: warning: format not a string literal and no format arguments
gcc: unrecognized option '-mylib'
file_util.c: In function âfile_moveâ:
file_util.c:98: error: âerrnoâ undeclared (first use in this function)
I don't know how to compile the library, and then compile the application without error/warning.
No need to use a for loop or generate intermediate object files:
(cd mylib && gcc -shared -fPIC -o libfoo.so *.c) && \
gcc -Imylib -o app *.c mylib/libfoo.so
Compile the library:
cd libfoo
for cfile in *.c; do
ofile=$(echo "$cfile" | sed 's#.c$#.so#')
gcc -shared -c "$cfile" -o "$ofile"
done
After this, you should have a libfoo.so file in libfoo/. Then, compile the program (Don't forget to cd back):
gcc *.c -I libfoo -L libfoo -lfoo -o application
The easiest is probably to get an IDE to do the build for you. Netbeans for one will create a Makefile so you can then build the project independently of the IDE.