This question already has answers here:
How to use external makefile in Eclipse
(3 answers)
Closed 5 years ago.
I have a project of multiple .c and .h files and I write my own makefile.
How can I configure Eclipse to use my makefile and my source files from their original locations?
You can create a custom Makefile and make sure it's in your project root. Then you need to disable the auto generated makefiles. You can do that by going here:
Project Properties (right click on project and select properties) -> C/C++ Build -> in that window uncheck "Generate Makefiles Automatically."
To use your own targets you can open the View called "Make Target":
Window -> Show View -> Make Target
In that view you can create a new target that will use the corresponding target in your custom Makefile.
There is an option to create a project from existing makefiles: use the "Project Wizard" and select "Makefile project".
You can disable "Generate makefiles automatically" in eclipse project properties -> c/c++ build (builder settings.)
In my latest attempt to compile a Cross ARM compile, I made a painful discovery on how to get this working.
First I created a "Makefile project with existing Code". I selected the Cross ARM tool chain. If I now open a console within Eclipse and make, it works.
Now to build within the GUI, I had to:
Change properties to Internal Builder, with Generate Makefile
checked.
The settings option now offers Build Artifact tab. pick executable with ${Project}.
Build. This will result in error in link stage.
Switch the settings to External Builder, uncheck "Automatic Makefile generation"
Clean
Build
All that you have to do is tell gmake to use your makefile. The default command for Code Composer Studio is ${CCS_UTILS_DIR}/bin/gmake. Simply tell gmake to use your own makefile (e.g. sri.mk). We do this with the -f option. So the default command would become ${CCS_UTILS_DIR}/bin/gmake -f ../sri.mk
Note that Code Composer Studio is Eclipse based.
Here are the instructions:
project->properties->C/C++ Build
click on the 'Builder' tab
Un-select 'Use default build command"
Change the command to ${CCS_UTILS_DIR}/bin/gmake -f ../sri.mk
Note that the build is kicked off from the Debug directory. The Debug directory contains the makefiles that are generated by Eclipse. I put my makefile in the top level directory of the project so that's why I put ../ in -f ../sri.mk.
Also, there might be a line that says "default: esh $(PLUGIN_SO)," or something along those lines depending on your project. I've found that changing the "default" to "all" will enable the project to compile too. This is a handy feature, eclipse :)
Related
I have a makefile C project on Eclipse.
When looking in the menu under Project > Build Targets there are a few options. These two interest me:
Build...
Rebuild Last Target
The basic question is what does Eclipse to differently in both cases? To be more specific:
What build goals does it set in the two cases?
Does it do anything different before invoking make?
Why can you rebuild only the last target?
You can create custom targets (Window -> Show View -> Build Targets). Those targets can have special parameters linked with your Makefile, by example it can change the verbosity, the level of optimization or even change the features included in your software.
When you use the simple Build command, Eclipse will execute the default build command which is usually make all. But when you use your custom target, then it's your custom parameters that are used, which could be by example :
make target_foo VERBOSE=1 BAR_OPTION=TRUE OPTIMIZE=TRUE
After this, if you use Rebuild last target it's your custom target which will be built.
As an example, working in embedded systems I usually have a mix of targets that enable or disable :
Code optimization (it's often easier to debug a code that wasn't optimized)
Debug printfs
Debug GPIO
With build targets you are allowed to add/use non-default make targets for your makefile projects.
Build targets/build lets you first select target from a list of targets then executes make "selected-target".
Build targets/build last target repeats build with last target selected via targets/build.
You might be looking at the wrong menu if you are only looking to build your makefile project.
You do that by Project/Build project. This by default executes "make all", but you can configure this via "Project/Properties/C/C++ build/Behavior".
I'm working with a CDT project in Eclipse/Neon.2 which cross compiles for an embedded target. I've added a bunch of .c files to the project and they are automatically included in the build except for (seemingly) one. In the project directory it is
STM32F7explore/Utilities/Log/lcd_log.c where STM32F7explore is the Eclipse project directory. If I try to build it manually, the Console window shows:
09:45:52 **** Building Selected Files of configuration Debug for project STM32F7explore ****
Info: Internal Builder is used for build
09:45:52 Build Finished (took 1ms)
For files that are included, the Console shows e.g.
09:54:50 **** Building Selected Files of configuration Debug for project STM32F7explore ****
Info: Internal Builder is used for build
arm-none-eabi-gcc -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16 -D__weak=__attribute__((weak)) -D__packed=__attribute__((__packed__)) -DUSE_HAL_DRIVER -DSTM32F746xx -DLWIP_TIMEVAL_PRIVATE=0 -I../Inc -I../Drivers/STM32F7xx_HAL_Driver/Inc -I../Drivers/STM32F7xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F7xx/Include -I../Drivers/CMSIS/Include -I../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM7/r0p1 -I../Middlewares/Third_Party/FreeRTOS/Source/include -I../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -I../Middlewares/Third_Party/LwIP/src/include -I../Middlewares/Third_Party/LwIP/system -I../Middlewares/Third_Party/LwIP/src/include/lwip -I../Middlewares/Third_Party/LwIP/src/include/lwip/apps -I../Middlewares/Third_Party/LwIP/src/include/lwip/priv -I../Middlewares/Third_Party/LwIP/src/include/lwip/prot -I../Middlewares/Third_Party/LwIP/src/include/netif -I../Middlewares/Third_Party/LwIP/src/include/netif/ppp -I../Middlewares/Third_Party/LwIP/src/include/netif/ppp/polarssl -I../Middlewares/Third_Party/LwIP/src/include/posix -I../Middlewares/Third_Party/LwIP/src/include/posix/sys -I../Middlewares/Third_Party/LwIP/system/arch -I../Drivers/BSP/STM32746G_Discovery -I../Utilities/Log -O0 -g3 -Wall -fmessage-length=0 -ffunction-sections -c -fmessage-length=0 -o Src/main.o ../Src/main.c
09:54:51 Build Finished (took 224ms)
I'm baffled by why Eclipse doesn't add the lcd_log.c file to the build. I've looked at the file properties popup and they look the same for both (and in particular, Eclipse does recognize lcd_log.c as File (C Source File)
I've deleted .metadata/.plugins/org.eclipse.core.runtime/.settings from the workspace and .settings from the project to force Eclipse to regenerate these and that did not fix the problem.
The project is on Github (https://github.com/HankB/STM32F7explore) but the requirements to build are a bit steep unless you happen to be developing for ST embedded processors.
Thanks!
What is going on here is the Log (or its parent Utilities) directory is not part of the source of your project, but rather extra files in the project that are excluded.
There are some visual clues in the project explorer. Compare the two boxes in red below:
As you can see the Src and dma2d.c files use different icons than Log and lcd_log.c.
You can re-enable the folder, or individual files, by right-clicking -> Resource Configurations -> Exclude From Build... and unchecking Debug and Release in the pop-up that looks like this:
You can also control what is included by selecting project properties -> C/C++ General -> Paths and Symbols -> Source Locations tab.
What I would recommend is that rather than having Drivers, Inc, etc be explicitly included, that you include all files in your project starting at the root. To do that, select all the existing entries in Source Locations and press Delete. You should then have just one automatically re-created entry /STM32F7Explore, like this: (Remember to do the same change to both Debug and Release)
Then, if you actually do want to exclude files/folders, repeat the above steps with Resource Configurations. CDT will be be quite helpful here, if you have individual files/folders under a source directory excluded from the build you will get yet another icon. Here I have excluded a single C file (log_lcd.c) and the Fonts directory:
Some of the specific help for Eclipse CDT that relates to the above:
Icon overlays appear at the bottom of the C/C++ Projects View help
Source locations tab help
I have some source code with a Makefile that builds just fine from the command line.
I followed the eclipse CDT instructions for importing a project with existing sources.
I opened the make file, and saw all the makefile targets in the Outline view.
I right clicked on one, and added it to the "Make Target" tab.
I double clicked it, and the console said it couldn't find that target:
14:24:13 **** Build of configuration Debug for project xxxxxxxxxx ****
make build-modules
make: *** No rule to make target `build-modules'. Stop.
Go back to the command line and type "make build-modules" and it works fine.
There are no other makefiles in this project. I do not know why this is failing like this.
1) Create a new project in Eclipse.
2) Import just the files that you already have.
3) Click build and make sure that you have clicked inside an open file of the project, that is open in the editor view.
User had to do also:
"Import project from Makefile" and that got my targets working.
I have NetBeans 6.9 installed and working fine on Ubuntu Linux 11.10. My goal is to set compiler options like -Wall and -std=c99 to be used by default. Currently, I have to right click on my project -> Properties -> C Compiler -> Warning Level to "More Warnings" and add -std=c99 to Additional Options. This is obviously a pain when creating many projects, and I'm sure there is a way to make all of this the default.
I found this thread which relates closely to my question. However, the only answer involves installing Code::Blocks and MSYS 1.0.11, which doesn't make much sense to me. I don't see how installing another IDE will help me, and MSYS seems unnecessary, as I am already using Linux.
I have tried every reasonable search term I can imagine, and am very surprised how little info I have turned up. It seems like most everyone who uses NetBeans should have to change this type of thing at some point. Terms I'm searching for: 'NetBeans -std=c99 default', 'NetBeans set default compile options', 'how to make NetBeans use c99 by default' and 'Code::Blocks settings into NetBeans'.
Here are some different things that you can do:
Copy and share the configuration files between projects, so you won't have to set every setting.
Create a default project, and configure however you like it. When you want to create a new project, just copy the default project and rename it to something else.
Modify your toolchain properties.
For details, see here:
NetBeans settings for GCC
You can create a Project Template Module. I was aware this is possible but didn't try it before, and this link is explaining how to do it;
https://blogs.oracle.com/seapegasus/entry/tip_create_your_own_project
(First you need NetBeans with platform SDK, not just C/C++ Bundle.)
I followed steps;
Open/Create your project with settings you want to use.
Create a NetBeans module project, choose a Code Base Name, i gave my.templates.ctemplate1
Add "Module Development > Project Template" to the module project. Choose your C project in "Select Project" step.
At next step select the Category as C/C++ and give a name for template i used MyCTemplate1.
Right click on module project and select "Create NBM", it will create my-templates-ctemplate1.nbm in the build folder of the module project.
Tools > Plugins > Downloaded , click "Add Plugin" and point to the nbm file in the build folder. Select install, it will give warnings because it's not signed.
When you want to create a new C/C++ project you will see your template in the wizard which will have all the settings as your first C project has.
Enjoy other possibilities; files, folders in original project will be there.
Have you tried editing your netbeans.conf file (for me, it's in /usr/local/netbeans-7.0.1/etc/netbeans.conf) and adding the options you need to the netbeans_default_options line? From looking at my version of the file, you might need to prepend -J to the switches (hence -Wall would become -J-Wall.)
I am new to Eclipse. Working on school project from source code provided by instructor. Project compiles without problems using provided makefile, but I want to compile/edit inside of Eclipse.
I have tried to import as Makefile project, but right away getting an error
make: *** No rule to make target `all'.
Here is a basic list of files.
Main:
Makefile
mm.{c,h}
malloc.c
mdriver.c
short{1,2}-bal.rep
Supporting:
config.h
fsecs.{c,h}
clock.{c,h}
fcyc.{c,h}
ftimer.{c,h}
memlib.{c,h}
Why I can't simply "Import" source, as I can do it in Visual Studio ?
Thanks !
CDT will attempt to build the project using make all, and it seems that your Makefile does not have that target. Easiest is to add:
all: your-target-to-make-stuff
to your Makefile. If you want to configure how CDT invokes make, you can right-click on the project, select Properties → C/C++ Build. Under the Behavior tab, you can select which make targets CDT should invoke when building and cleaning.
I don't have an Eclipse with C/C++ plugin at my hands right now, but I have an idea what it could be:
It appears that your Eclipse is starting make with the specific target 'all', which doesn't seem to exist in the Makefile - you should be able to reproduce this behavior on the command line with the command make all instead of just make.
If this is the case, there are two solutions: one is to modify the Makefile to introduce a target 'all'; or modify the C/C++ builder settings in Eclipse to execute the make without any argument.
You can install the C/C++ for developers plugin.
Or in many cases I would use Ant to create or call make files.