User forums > Using Code::Blocks
Adding files to a project created with cmake
gib:
I think I know the answer to this question, but I want to be sure, and possibly get an explanation.
I am working with a project (C + Fortran) that was created from CmakeLists.txt like this:
cmake -G "CodeBlocks - MinGW Makefiles"
I thought I could add source code files to the project via 'Add files...', but when I build the project the added code is not found and the link fails. It seems that CB is using the previously created makefiles (the 'Custom makefile' box is ticked in Properties) and ignoring the displayed list of files. If I untick the Custom makefile box I get build errors, whether I choose GNU GCC or GNU Fortran as the compiler. There is always the option of adding the files in CmakeLists.txt - that works.
I know that when I create a project within CB, without using cmake, I can add files any time. With a cmake-generated project, is it always necessary to edit CmakeLists.txt and rerun cmake? If it was just a matter of adding the source files it would be a non-issue, but when many libraries and search paths have been added within CB the changes needed in the cmake file become much more complicated, in fact I'm not sure how to make them. Adding them again within CB after rerunning cmake can be rather tedious.
I'm really trying to get a clearer idea of what happens 'under the hood' of CB.
Thanks
Gib
Modify message
Jenna:
You should ask this in a cmake-related list.
Using custom makefile-projects (like cmake does) is not the preferred way to use Code::Blocks.
--- Quote from: gib on July 04, 2017, 11:47:19 pm ---I'm really trying to get a clearer idea of what happens 'under the hood' of CB.
--- End quote ---
Code::Blocks just runs the makefiles and files, search paths or libs added to the project in C::B are (of course) not known by the makefile.
gib:
Thanks jens, that confirms what I suspected. I will explore creating this project within CB.
gib:
I now have a working project that was developed within CB. This is definitely preferable to what I was doing with cmake.
One comment: in a project like this with mixed languages, C and Fortran, when I set the Project Build options for the C compiler, it automatically assumes that this has become the Selected compiler, requiring me to reset it back to Fortran. Is there a way to change the options for one of the compilers without changing the compiler selected for the project? (Fortran needs to be the selected compiler in this project.) It's a minor issue.
gib:
Hi jens, I've noticed that the .cbp file sometimes gets created with two <Linker> sections, one contained within the <Build> section, the other outside and after it. I presume this is because the project uses two compilers, and maybe the <Build> section refers to C. If these two <Linker> sections are not consistent build errors can result. I have found that it is safe to delete the first <Linker> section (the one inside <Build>). When the Project Build options are changed in CB, the change in the project file occurs only in the <Linker> section outside the <Build> section, so after that first section is deleted it doesn't get replaced (so far!).
The moral of the story is that I have to remember to check what's in the project file. By the way I'm still using version 13.12 - maybe the latest version has different behaviour.
Cheers, Gib
Navigation
[0] Message Index
[#] Next page
Go to full version