Whenever I drag and drop C files into my CLion project, errors occur as the makefile doesn't update. I've tried Reloading the CMake project a bunch of times and, when I try to re-compile the makefile, it says
Cannot compile file 'Makefile'. Cannot find run configuration for this file.
So, how can I perform this simple transaction of pasting files over into my CLion project without causing large issues?
You can just edit your CMake file and add there the .c/.cpp files you just added to your project.
This will fix what you said.
Nevertheless when I do that, the code inspection stops working and all the errors don't underline.
Let me know if you have the same problem.
Related
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")
I can't navigate through a project in Eclipse (Oxygen.3a Release (4.7.3a) with CDT version 9.4.3.201802261533). The project is built successfully but I can't trace back many functions using ctrl+LMclick.
I tried fixing the problem from online resources, but many suggested modifying the entry of Preprocessor Include Paths, Macros etc, which my project does not even have. What is the reason behind this and how do I fix it?
For some reason, the next entry (C/C++ Include Paths and Symbols) shows that |Include path not found"
When I try to trace a function, I get the "Could not find symbol "xyz" in index". I have already tried rebuilding the indexer but it did not work for me.
In my experience, the absence of the Preprocessor Include Paths, Macros etc. preference page happens in newer versions of CDT when you select the new Makefile Project option in the new project wizard, whose description is
(Experimental) Create a new project that builds with the 'make' build
tool using CDT's new Core Build System.
I would avoid using this as it's experimental, and would select instead C Managed Build (or C++ Managed Build). On the next wizard page you can still make it a makefile project if you want.
I ran into this problem trying to use cmake4eclipse. I forgot to heed the warning in the help file, which explicitly state:
"Do not choose the New C/C++ project wizard, as that will take you down the road of CDT`s new project type (which has poor cmake support)."
What this means is that, for the entry to appear in an executable / library -type project (not Makefile project), you have to do this now:
File --> New --> Other...
Choose "C++ Project" (not "C/C++
Project") under the C/C++ category:
P.S. Also, I had to remake the folder and copy all the sources there, i.e. when I tried the old wizard on top of a "deleted" project, something didn't override correctly and I was still missing "Preprocessor Include Paths, ...". Deleting .cproject and .project files within the folder before recreating works too.
Depending on your project, you may need to include the path of the toolchain manually. It wasn't for me. So for my project I did the following:
Go to Project – Properties – C/C++ Include Paths and add there “C:\Program Files (x86)\GNU Tools ARM Embedded\5.4 2016q3\arm-none-eabi\include” (change to fit your installation). Then refresh, clean and build the project. Finally, rebuild the indexer and this should work.
I just installed Eclipse and I get this error whenever I hit the button run: Launched Failed.Binary not found.
What should I do? Please if you can explain step by step.
Thank you.
Start eclipse the same as you would any other program,
generate a 'project'.
add files to the project,
then clicking run will trigger a compile of all the files, which creates the object files. then a link of all the object files (and needed libraries) to produce an executable, then it tries to run that executable.
I.E. run does nothing useful until the project is fully created and will have plenty of failures until the compiles have no errors and the link has no errors
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).
I have an Eclipse project that I need to auto-generate some files before compiling it. I do not want to put this auto-generated files in my repository, so each time I compile the projetct I perform a pre-build to auto-generate this files.
The problem is that this auto-generated files are *.c and *.h files, and in the first time I compile the project, the following happens (in this order):
pre-build: auto-generate some *.c and *.h
build: eclipse will not build this auto-generated files
If I compile again, this files will be compiled. Maybe this is happening because of the discovery process of what files eclipse will compile. Before initing compilation, we do not have this auto-generated *.c and *.h files.
In the second time we compile, we already have this auto-generated files, so this files are compiled.
If you want full control over when exactly the custom build step takes place, which files need to be refreshed after it, the environment, the working directory etc.. do not specify it as a simple pre-build step. Go to the project properties -> Builders -> New... and choose "Program".
In the resulting dialog, you have much more control over the execution of your tool. For instance, you can make your tool run whenever the XML file is saved, and you can tell eclipse to refresh all the auto-generated files whenever it is run.
If I understand your question correctly, it seems that building your project the first time will auto-generate the necessary *.c and *.h source files, but the project will fail to fully build because these source files are not found immediately. After a small delay, Eclipse recognizes that there are new files added to the project and you can then build a second time and everything will proceed normally. Does that sound about right?
Assuming this is the case, my immediate thought is to write some sort of script or makefile so that all of these actions can take place in the proper order, with a single action. Depending on how dirty you want to get your hands, here's a link ;)
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.cdt.doc.user/concepts/cdt_c_makefile.htm