I have a c program that I need to compile and use in the middle of a python code. it is not c++ program so I assume I should change this syntax for compiling because I get a lot of errors related to not having "main()" in the program which is just because it is a c (not c++)for a x86_64 Mac system?
how should I change this syntax for a program.c code?
g++ -o program.x program.c
Your C code should be compiled into a shared library:
gcc -shared -o program.so -Wall -Wextra -fPIC -O2 -DNDEBUG program.c
And then you can use ctypes module to invoke functions in your library from Python.
Related
I am trying to debug my c program using
gcc -g -lm -lpthread -std=c99 -w terminalproject.c
and then
gdb a.out
but when I type
layout next, it shows me assembly code not c code.
How to switch to C code in layout?
EDIT: I am using Red Hat Linux 6, I tried to run it in Ubuntu, It is showing C code.
p.s my code has pthreads in it.
This command:
gcc -g -lm -lpthread -std=c99 -w terminalproject.c
is wrong. Use this instead:
gcc -g -std=c99 -pthread terminalproject.c -lm
You should never use -w (suppress all warnings) flag, unless you desire painful debugging sessions.
layout src says No source Available.
This likely means that you are using updated GCC, but ancient GDB. Try building recent GDB release from source -- it's usually not hard.
such as:
gcc test.c mystaticlib.a -o test -O2
would -O2 take effect for mystaticlib.a, or just test.c?
-O2 is a compilation flag. The only input you're compiling in this example is test.c. mystaticlib.a is not compiled, but rather linked with the compilation output of test.c to create the executable test. Since mystaticlib.a isn't compiled here, the -O2 flag does not affect it.
My final executable (this is in unix though) will be proj07.
proj07: /user/cse320/Projects/project07.driver.o proj07.support.o
gcc -Wall /user/cse320/Projects/project07.driver.o proj07.support.o
proj07.support.o: proj07.support.c
gcc -c proj07.support.c
This creates proj07.support.o but no proj07 exists after compilation. I don't get an error so my mistake must be simple but I can't seem to figure it out.
Here's the output:
gcc -c proj07.support.c
gcc -Wall /user/cse320/Projects/project07.driver.o proj07.support.o
Also I am to use a static driver to test my file which is why the path is like that
You probably do have an a.out executable. Add -o $# to your first gcc occurrence and you should be fine.
How can I force GCC to compile with threadIdx lines in my code?
I'm attempting to compile my cuda application with a c wrapper.
To generate the .so file I run:
nvcc -arch=sm_11 -o libtest.so --shared -Xcompiler -fPIC main.cu
Then I attempt to compile the c wrapper with:
gcc -std=c99 -I/usr/local/cuda/include -o main -L. -ltest main.c
This results in the following error a few layers down in my code(an include to an included file):
error: ‘threadIdx’ undeclared
Note: Everything does compile and run just fine as a GPU application without any C wrapping.
Gcc has no capability to compile the cuda part of the code. You need nvcc to compile the code. gcc does not know what to do when it came across threadIdx is.
I am using alchemy to compile the C code.
This is the way I am compiling
gcc oggvorbis.c -O3 -Wall -swc
oggvorbis.swc -lvorbis
I am getting an error
llvm-gcc: oggvorbis.swc: No such file
or directory.
But the command works fine when i don't use any shared library.
Your command line invocation should probably read (untested)
gcc oggvorbis.c -O3 -Wall -swc -o oggvorbis.swc -lvorbis