Compile error in c files - c

I have a c file inside "examples" folder inside ArtoolKIt that I want to compile in Ubuntu.
Artoolkit works perfectly, but how can I compile this c file from terminal?
I try ./helloWorld but it gives me this error:
No such file or directory
Is there any specific way to compile Artoolkit programs cause I don't see it in its docuemntation.

Use either gcc or clang to compile .c files:
gcc -o hello ./examples/filename.c
the parameter following the -o flag names the file that will be produced by the operation, a parameter without any flag named the source input file.

So, the problem that I had was with my directories! For this wo work you should have inside teh folder Examples of ArtoolKit the thiungs: a folder with data, your c file to be compiled and teh makefile in case you have it so youy can compile with $make command.
Now It works for me!

Related

Compiling dynamically linked library in a makefile

I am trying to run my library using a make file. I currently have a dynamic library called libname.so which I created by linking the object files of some of my C files. This library works correctly when I run the following lines of code in my linux shell :
gcc -L. main1.c -lname -o out
LD_LIBRARY_PATH=.
export LD_LIBRARY_PATH
But when I copy these exact lines of code in to a make file and name the make file title for this function 'names' and then run 'make names' in linux shell, I get the following error:
./out: error while loading shared libraries: libname.so: cannot open shared object file: No such file or directory
Then once again when I run the final two lines of code shown at the end of the makefile function again then run the out file, it is fixed and the program works again.
I just need to figure out how to make it work directly from the makefile.
LD_LIBRARY_PATH=.
export LD_LIBRARY_PATH
These two lines do not influence the creation of the program in any way because you type the lines after creating the program.
These lines are not used for building your program, but they influence running the program (by typing ./out).
If you compile your program using gcc directly (not using make) and open a new terminal, you also have to type these two lines (again) before you run the program.
It does not matter how you build the program (by typing gcc manually or by running make):
After opening a new terminal, you will need to type these two lines before you run the program.
However, the dynamic linker does not only use the path information from LD_LIBRARY_PATH but also from the DT_RUNPATH information in the executable.
Unlike the LD_LIBRARY_PATH variable which is set on one console (or terminal) only, the DT_RUNPATH information is stored directly in the executable file.
As described in another question on this site, you can set the DT_RUNPATH information using the -Wl,-rpath=<value> switch:
gcc -L. main1.c -lname -o out -Wl,-rpath=.
If you do this, the dynamic linker will search your library (libname.so, if I understand correctly) in the current directory.
Note:
. really means: In the current directory; it does not mean: In the same directory as the executable file!
If your program is stored in the directory ./somedir and you type somedir/out, the file ./libname.so is searched, not the file ./somedir/libname.so.
This is both the case for the -Wl,-rpath= method and for the LD_LIBRARY_PATH= mehtod.

How to use functions in a package that is written in C in a different location

I am trying to use a linear algebra package called hnfprof. I have done the installation with the given instructions and now its ready to use. Now I want to use some functions in hnfproj/src/lift/lift.c file. I want to create my own matrix examples and check outputs for each functions separately. I am not clear how to do this. (I know only basics of C language, creating .c files in a folder and running it in my Ubuntu terminal.)
I know that I should write a C file including this "#include <lift.c>" file name and creating a matrix in my file "main.c". I don't know how to include a file name in a different location. When I compile I can not use "gcc -o program main.c lift.c". My "main.c" file is in a different folder. I don't want to create any make file inside the package folder. So how I can just use the "lift.c" file inside my "main.c" file which is in a separate folder "Main" and create all executable make files inside "Main" folder?
If its difficult to give a answer, appreciate if you can suggest me some source to learn this. Thank you
No need to include lift.c directly in main.c, and you can call function in lift.c from main.
When it comes to compilation, you can use:
gcc -o program main.c file_location/lift.c
If you need other options, add them (most flags at the start; libraries at the end, after the source code). You can also compile each file to object code separately and then link the object files together:
gcc -c main.c
gcc -c file_location/lift.c
gcc -o program main.o lift.o
refer
Compiling multiple C files with gcc

Cannot get gcov to produce any coverage data

Failing to get gcov coverage file with my C/C++ Makefile project with googletest on Windows with mingw32
Full source code at https://github.com/rusefi/rusefi/tree/gcov/unit_tests
I have
USE_OPT += -fprofile-arcs -ftest-coverage
ULIBS += -lgcov --coverage```
and I get .gcno files next to my .o files in build\obj folder
I execute rusefi_test.exe and I see no new files with coverage data :(
nm rusefi_test.exe
confirms that gcov is inside my binary
I've already added explicit flush at the end
extern "C" void __gcov_flush();
__gcov_flush();
but I still do not see any
90.00% of 10 source lines executed in file tmp.c
style line at the end of stdout
I've tried copying my .exe from build to build\obj folder but this did not improve anything.
It looks like my compiler has something to do with this! I've moved to a simple HelloWorld.cpp application and depending on compiler I either get runtime file or not!
main.exe produced by "g++" from cygwin produces the runtime file while x86_64-w64-mingw32-g++ from cygwin does NOT produce main.gcda file!
x86_64-w64-mingw32-g++ bundled with cygwin seems to be affected while same x86_64-w64-mingw32-g++ downloaded directly from mingw64 seems to work.
There is https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=854368 which they say is closed but at least tells me that sometimes it's about the compiler itself :(

Compiling c program with dependencies, h and h0 files

I am trying to compile the gjh solver - written in C - into an executable file in windows. It is available on netlib
I downloaded the c file and am using gcc compiler via WinGW on windows' command prompt. Trying to compile the gjh.c file directly gave me an error that says:
gjh.c:33:21: fatal error: getstub.h: No such file or directory
#include "getstub.h"
compilation terminated.
I assumed that compiling gjh.c requires the dependency getstub.h.
getstub.h is not the only dependency required, there are other dependencies, namely: arith.h, asl.h, funcadd.h, and stdio1.h. All of these files are available on the same link where I found getstub.h. However, arith.h0 and stdio1.h0 are available instead of arith.h and stdio1.h.
Are these files the same? I tried to rename the .h0 files to .h and tried to compile gjh.c, but I got this error:
collect2.exe: error: ld returned 1 exit status
Are the two files the same? If not, is there any way for me to compile the gjh solver successfully into an .exe?
If that's the only problem in compiling, try using the -I switch in gcc:
gcc -I/my/path/to/include/files -o gjh gjh.c
the -I switch hints to gcc where to find your #include files.
I am not sure about the stdio1.h. I think your approach to rename is OK but that reference to external functions such as Sprintf. You need to link with a library defining that. If you know where it comes from, use the -L and -l switch in gcc for that:
gcc -I/my/path/to/include/files -L/my/path/to/library -lnameoflibrary \
-o gjh gjh.c

GCC compiler errors with “No such file or directory”

My Ubuntu version is 14.04 LTS. I have a C program copied on the desktop by the name sendRawEth.c. When I write:
gcc sendRawEth.c -o sendRawEth
The compiler complains:
gcc: error: sendRawEth.c: No such file or directory
gcc: fatal error: no input files
I have no idea how to solve this error.
please do the following.
On terminal check the present directory by 'pwd' command and then check the directory in which your programme is there and see if they are same or not. And while writing gcc yourfile it's case sensitive. Hope this helps
There are 2 reasons for such errors.
You said you copied your C programs in your desktop folder.
This means you may have only copied sendRawEth.c. file format not the executable file.
You should ensure you copy the .exe files as well.
You need to change the directory to the same folder that you copied your programs into.
First, check your current folder by typing pwd.
Then change it to your required folder with:
cd /outerfolder/your program folder
Then compile it with:
gcc -o programname programname.c
And finally execute it with:
./programname

Resources