Compiling with SDL in different directories - c

I'm trying to do a project which uses SDL2 to do the graphics.
I want to have my project files in a directory.
I have the functions that manipulate the SDL directly and pictures in a subdirectory of this (UI_library).
I solved the compiling part by adding to the compilation commands
-LUI_library
The problem is that when I run the program, it can't find the pictures, since it assumes they are in the project directory and not in the subdirectory.
Do you know how to fix this without manually changing the code in the subdirectory? There are a lot of references to the pictures in the library.

One way to solve this problem would be addressing the whole path to your file.
For Example:
Windos:
SDL_LoadBMP("C:\Documents\your_image.bmp")
Linux:
SDL_LoadBMP("/home/tigre200/Documents/your_image.bmp")

Related

Dealing with include files in C / zephyr-rtos

I have a little project where I want to use the ESP32's ADC, and I want to use zephyr as my RTOS. I am using one of the examples provided by the ESP-IDF to set the register and read input from the ADC pins. This example works if I use the idf.py tool and within the same folder. Now I try to use west to build and flash this project into the esp32 with zephyr running on it, however when I try to build the project west cannot find the header files/source files specified inside the program. I have tried using absolute paths in every header file, moving the project+include folder to the zephyr workspace, initializing west inside the esp-idf workspace, etc... None of this has worked for me.
I suspect something along the cmake files is messing up with my project, but I really cannot pinpoint exactly what that is. My question is, how can I deal with header/source files that are outside the zephyr workspace? My folders look something like this:
Zephyr workspace
|-------ADC target project (copied originally from espressif folder)
|-------include files from zephyr
Espressif workspace
|-------ADC original project
|-------include files from espressif (I want to link this files to zephyr)

How do I create a CMakeLists.txt?

I am starting to learn about CMake and have two questions:
1. Do I need to update the CMakeLists.txt file every time When I add a new file?
Assuming that the size of the project grows, the number of subdirectories and source files in the project will also increased greatly.
In such a case, I guess it is inconvenient to update the CMakelists.txt file whenever a new file or directory is added to the project.
Or is it part of the code management? How is it usually done?
2. In order to build a C Eclipse project(makefile) using CMake, should I write the CMakeList.txt manually?
There are many ways to import CMake projects into Eclipse, but I can't see how to build a C Eclipse project with CMake.
Do I need to update the CMakeLists.txt file every time When I add a new file?
CMake, like GNU make, allows to use wildcards to specify source files.
However, it's good practice to explicitly list files to build, in order to avoid silly mistakes (due, for example, to missing or unexpected files in source directory).
When file list becomes large, build definition files (like CMakeLists.txt) may be split into multiple files.
In order to build a / C Eclipse project(makefile) / using CMake, Should I write CMakelist.txt manually?
I don't know aboud Eclipse, but many IDEs partially/completely automate CMakelists.txt creation. Maybe Eclipse has such a tool too.
Yes write your CMakeLists.txt manually. This can barely be automated, beside adding new header files. There is a way to include all *.h files, but it is not enouraged.
And add every new header file manually. C files are not needed. Adding header files should not happen ofen.
Writing your own CMakeLists.txt files is recommended (at least you understand how CMake works). However, for larger projects it makes sense to automate it. I decided to post my own CMake generator https://github.com/Aenteas/cmake-generator so anyone who wants to implement their customized version could adopt some ideas from here (as it is not likely that my generator would suit your needs perfectly).

How to make multiple subdirectories in Eclipse from existing code

I am using Windows 10 and Eclipse Mars edition 32 bit. Programming in C
I am trying to learn C from a Lynda.com course C Essential Training. The course provides a zipped directory with many .c and files and a few others like .h files as you can see below.
However in the video he managed to get each .c file and related source code into its own directory structure.
I've tried numerous type of imports and I also used a batch file to put each .c file in its own folder and tried importing that. I was able to get the Eclipse IDE project window to look like the instructors, but as soon as I tried to compile individual .c programs the project kept looking in the primary workspace folder which for me is C:\Source\Testing\workspace and error'd out.
Is there an import option to create this type of subdirectory structure automatically? I want to go through the tutorial and build and execute each .c file individually. However what I have had to do is put the .c file into a single folder build it and run it one at a time. I then have to delete the source and debug folder and start over for each lesson. There must be a better way.
Eclipse workspace is streigh connected to FS.
This means that your workspace in Eclipse is a folder on your hard disk or where it is stored.
What you can simply do is to create a new folder using right-click-popup-menu within Eclipse Project Explorer and then copy/move files into the new folder.
Or you can create a new folder into your workspace directory and copy/move file inside, then you must refresh Eclipse workspace.

what is the best way to port native project into Android App?

I have a project written in C; it has up to six sub-directories with .mk files, a make directory, at least one makefile, and Android.mk files.
I have used Android Studio, ndk, and JNI to build a project which compiles and runs. Now I want to port the above project into it. I have read all the GNU make manual, and know that I can include other make files. My question is would it be better to use gradle to include the make files above, and can I even do it? I have not read the gradle manual yet. It is my understanding that it is a build environment; I am not clear on what are it's differences / similarities with make. And if I can use it to complement make or I just have to pick one and go with it. I did have to edit it to get the JNI project working. My initial goal is to just run the make files in the native project in silent i.e. have them not produce any .o files and see what they do and validate that I am including them; then I want to include all the .c files and build .o files. I know I can do this with include statements in make file and since I have an Android.mk file in my project, I think I can do it through that. But I wonder if in the long run it is better to use gradle. What should I do please?

relative path and system paths are not working in codeblocks

When I am trying to access files from standard usr/ it is not working. and showing errors that file is missing .
I have added path but and make it work but i think this is not the correct way.
I have a workspace with 10-12 projects which are of c and cpp both.
In one project I am using cpp with thrift libraries and protocol.
in that project only I am facing issue. with I am individually building that project it is working but when building it from the main project. it starts showing error in files.
There all almost 17 projects and 16 are generating .so files and all are going to the main project. and main is generating an executable. and that executable uses all the .so files.
but In thrift only it is showing errors. before it was showing for #include i added that file so now it is showing undefined type Name Space ..
I think this issue is because of relative path but I am not sure
Please Help

Resources