Cannot access header files in separate folders - c

I'm pretty new to coding in c, but I have sample code that I imported into the eclipse console. However, when I go to build the project I run into various errors. All of these errors are because a code that I have in one folder is not able to access code in another folder. For example my main function is located in project>src>main.c but is not able to access the project.h file located in project>headers>project.h. I am also no able to access code directly above in the hierarchy either. For example, my project>src>compiler>comp.h is not able to access project>src>calc.h file. Is there a way I can instruct the code to find it? I have tried using #include "../src/calc.h" in my comp.h file but I still get the error message "No such file or directory." Any suggestions would be very helpful.

Header files can be tricky to include, it depends where you are compiling.
Try to compile like this :
gcc -o myBinary <your .c files> -I./your/path/to.h (it will link your .h files at the compilation state)

The best idea would be to create a Makefile and configure it to make your header files works in every files of your project, have a look at How to create a Makefile.

Related

Libdvbcsa, missing header files

I have a problem i cannot solve.
Library repository
I am trying to run test .c files in this library, I have installed the files however when I run this on mac:
gcc testbitslice.c
I get this error
fatal error: dvbcsa_pv.h: No such file or directory
#include "dvbcsa_pv.h"
the testbitslice.c file calls the header files as follows
#include <dvbcsa/dvbcsa.h>
#include "dvbcsa_pv.h"
When I checked urs/local/include there are one file under dvbcsa folder which is dvbcsa.h. But there is no file called dvbcsa_pv.h. I don't understand the problem. I don't get error while installing with ./bootstrap or ./configure and make, make install commands.
Then, I manually copy/paste header files from package folder to usr/local/include, this time it gives error as
Undefined symbols for architecture x86_64
Is the problem related to installation or something else? I would appreciate if you could help me
I have found out the problem. I just had to show the library directory i want to use using:
-I/Users/bill/Desktop/libdvbcsa-master/src/dvbcsa
and it works.

How to make the dynamic link possible

I am using ssh to do some computing in a server. But I am completely new to unix. I have a .so file needs to be linked to the program. However, when I run the program, it reports the following error
MatMult.so: cannot open shared object file: No such file or directory
Link error: 'MatMult' cannot load dll
Link error: 'MatMult' undefined function
I think I need to change LD_LIBRARY_PATH to make the .so file on the path. But I have no idea how to write it. The original line is
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OXHOME/bin64:$niqlowHOME/include:$OXDEV
My question is how to modify this line to make the link possible. And is there any resources you would recommend for me to read to understand what does that line do.
If you are compiling some program which requires linking to the said '.so' file, then you can use:
gcc -L[path of the .so file] -o output -l[library name]
And if you are running a program that requires .so library, simply copy the library file to /usr/lib directory.
Otherwise please elaborate your query. Thanks

how to recompile include files in eclipse

i want to recompile my include files of my project,which includes some header files and .c source files which are files for my Ethetnet driver. Now i want some change in one of my included source file. but when i change and build or rebuild my project, the change in the include .c source file does occur in the final output binary. that means my project taking previously compiled included .o files. So how can i recompile my all include files of the project so that change occur in final output binary.
Thanks in advance.
CMIIW but AFAIK it depends on your compiler (which I guess is gcc), dependency analysis against included files may be done or not, and in gcc case it does NOT do it. It only compares .c against its corresponding .o, so you have to force rebuilding when you change the include file. There perhaps certain compiler options you can use, but I don't know for it.
EDIT:
Just found a similar question: How can I have a Makefile automatically rebuild source files that include a modified header file? (In C/C++)
If you are indeed including the right file (the ones that you have modified, not some with same name from some other directory) then cleaning a project and rebuilding it should help. Just select a project in project explorer, right click, do "clean project", then build it...

Project needs assistance with header files

I am currently working on a small project that runs off of a completely custom built version on linux. I have a copy of all the header files that are in /usr/include on the customer OS however I really dont get along with that OS so i want to carry on the project from my fedora box. I tried creating a new directory in the fedora's /usr/include however it throws up a hissy fit everytime it comes to compile. Is there a way that I can tell the compiler to go to another directory for header files, e.g. /usr/include2?
Thanks
-I /usr/include2 (though /usr/include2 is of course very bad name for this purpose).
See compiler's -I option. It allows you to specify where to look for header files.

Having CMake put generated binaries in a specific directory structure with assets

My project's directory structure is basically as follows:
root/src
root/assets
root/library
I currently have CMake set up to compile the source, compile the library, and then link them, by calling make from the root directory.
I then have to manually move the executable into the original assets directory to get it to run, since that's where it expects to be (and we want to test with our directory structure in assets as close to what we expect it to be when it's done).
So, is there any way to tell CMake to automatically stick the compiled binary in that directory, as well as copy the assets over? Since we're doing out of source builds, sticking the executable back into the original project source's assets folder seems odd.
In short, two questions: Is there any way to get CMake to copy assets as well as code, and is there any way to have it copy the generated executable to a specific location in the build tree?
Any help would be appreciated --- thank you!
Here's a simple example with a structure like yours:
root/src/main.cpp (only source file)
root/assets (where I want the executable to go)
Here's the cmake file:
PROJECT(HelloCMake)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${HelloCMake_SOURCE_DIR}/assets)
add_executable (HelloCMake src/main.cpp)
When I build against this using Visual Studio I get the output placed in root/assets/debug. I'd have to dig to figure out how to get rid of the extra configuration folder (debug). Not perfect, but hopefully that gets you on the right track.
Edit...Even better:
INSTALL(TARGETS HelloCMake DESTINATION ${HelloCMake_SOURCE_DIR}/assets)

Resources