NetBeans not parsing CMake defines - netbeans

I'm using NetBeans to work on an existing CMake project.
In CMakeLists.txt there is
set(DEFINES ${SRC}/defines.cmake)
So when in source you have
#ifdef MY_OPT
//do stuff
#endif
these are blanked out in NetBeans, because there is never a
#define MY_OPT
Instead there is a
-DMY_OPT
in defines.cmake.
How can I tell NetBeans to look into this file (and others)?

set(DEFINES ${SRC}/defines.cmake)
What is this line intended to do? If your defines.cmake contains some preprocessor settings, you better use include():
include("${SRC}/defines.cmake")
Is it possible that this defines.cmake file actually sets the defines through the pre-processor instead?
Yes, this is where add_definitions() will help:
add_definitions(-DMY_OPT -DANOTHER_ONE)
To sum it up:
CMakeLists.txt
# ...
include("${SRC}/defines.cmake")
# ...
defines.cmake
# Add defines
add_definitions(-DMY_OPT)
Somewhere in your source:
#ifdef MY_OPT
/* This is used now */
#else
/* MY_OPT is not defined - shouldn't happen now */
#endif
Btw., you may also have a look at configure_file().

Related

Compiler generates FPU instructions

I realize a CMSIS Project solution with VS Code but I've an error on an include file :
#include "stm32f10x.h"
And I've got this error :
In included file: "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"clang(pp_hash_error)
core_cm3.h(90, 6): Error occurred here
The path of this file is here :
C:\Users\"name"\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.0\Device\Include
But I think I forgot something during the configuration.
I justa want to build my C file but VS code doesn't make the link between my .h and my CMSIS project.
You are never supposed to #include "stm32f10x.h"
You only #include "stm32f1xx.h" and it will include the other headers you need.
You must also define a macro on the command line, one of STM32F101x6, STM32F101xB, STM32F101xE or STM32F101xG.
For most compilers you can define this with an argument like -DSTM32F101xB.
After that you will need particular command line arguments that match your chosen processor, such as -mthumb -mcpu=cortex-m3 -mfpu=none.
Maybe your error was specifying an incorrect -mfpu=.

VSCode IntelliSense cannot understand CMake add_definitions

VSCode IntelliSense cannot understand CMake add_definitions.
What can I do for this.
When I use add_definitions in CMakeList.txt.
add_definitions(-DTEST_READING_DEV_ID)
In c file I use
#ifdef TEST_READING_DEV_ID
...
...
#endif
The code block looks like grey.
Use cmake generate file compile_commands.json. Add this in CMakeList.txt
target_compile_definitions(app PRIVATE CMAKE_EXPORT_COMPILE_COMMANDS=1)
Build the project.
Add the file compile_commands.json to VSCode Extension settings file c_cpp_properties.json.
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
This article explains the scheme for the c_cpp_properties.json settings file.
https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference
Now, the code block is not grey.

autoheader creates VERSION macro conflicting to other variable defined in other header file

My configure.ac file has line as below
AC_INIT([myApp], [1.2.3], [dev#company.com])
then autoheader/configure will create config.in in which we will have 2 macros as below,
/* Define to the version of this package. */
#define PACKAGE_VERSION "1.2.3"
/* Version number of package */
#define VERSION "1.2.3"
I also need build sqlite in the same project and sqlite header file also defined variable VERSION, then I got error like below
../../config.h:117:17: error: expected unqualified-id before string constant
#define VERSION "1.2.3"
^ ../../SQLiteCpp/include/SQLiteCpp/Database.h:35:21:note: in expansion of macro ‘VERSION’
extern const char* VERSION; ///< SQLITE_VERSION string from the sqlite3.h used at compile time
I have to manually modify config.in to comment out VERSION macro every time to let build continue. My questions are:
Why 2 macros created in config.h, PACKAGE_VERSION and VERSION looks the same, what is the difference?
How to resolve this VERSION macro/variable conflicting issue?
Thanks
Why both VERSION and PACKAGE_VERSION? Probably backwards compatibility.
How to avoid defining VERSION? The AM_INIT_AUTOMAKE documentation in the Automake info page ends with a paragraph dealing exactly with how to avoid PACKAGE and VERSION being AC_DEFINEd:
AM_INIT_AUTOMAKE([... no-define ...])

Where to add new .h and .cpp file in STM32CubeIDE project

I used STM32CubeIDE to create a new (C++) project for my nucleo-f411re board by File > New > STM32 Project. The project was created as usual. I renamed "main.c" to "main.cpp" since I selected C++ as the target language. A simple "blinky" compiles and runs correctly on the board. So now I want to begin adding some C++ code to the project.
The "main.cpp" is in the project tree under myproject > Core > Src > main.cpp. If I want to create some new source/header files, say "foo.h" and "foo.cpp", I think I can right-click on something in the project tree, then New > Header File or New > Source File. But the question is -- what do I right-click on to create the source/header file? I assume the file will be created in the location (= folder) I right-click on. Where do I want to put them? Both of them in the "Core" folder? Separately in "Core > Inc" and "Core > Src" folders? I'm not sure.
Edit: I added the header/source files to Core > Inc and Core > Src respectively, and that seems to work. Is that recommended? I wonder if they will still be there if I change the configuration, causing the code to be regenerated.
I know this is a very late answer but I didn't find a lot of tips regarding this question a while ago so here is my take on it.
Basically you can place source file in any source folder.
You can use existing folders or create a new one, however you like.
Header files have to be placed inside a folder that is in the include path (e.g. Core/Inc) or you have to tell the compiler that a specific file should be included.
If you want to create a new folder for your header files you have to add the folder or files inside this folder to the include path via Project -> Properties -> C/C++ Build -> Tool Setting (tab) -> MCU GCC Compiler or MCU G++ Compiler -> Include paths.
Note that you might have to add it twice, once for C files (MCU GCC Compiler) and once for C++ files (MCU G++ Compiler).
To create a file you can simply click on the folder you want to create it in and add a new <whatever>file.
You can also just create files and directories on your local filesystem and refresh the project (right click -> Refresh or F5) to show changes in STM32CubeIDE.
For small projects (like a blinky project) it is probably enough to just use the Core folder.
For bigger projects I personally like to seperate all the autogenerated code from my own files.
Especially for C++ projects it can become very annoying that STM32CubeIDE always renames main.cpp to main.c and deletes code segments you accidentally put outside their comment blocks every time you run the code generation.
I usually create a Project source folder for project specific files and a Lib source folder for libraries.
Then I create a cppmain.h file that simply declares a void cppMain() function and a cppmain.cpp file that I use to write my main program.
The only change to the autogenerated code is that you have to include cppmain.h and call cppMain() before the main loop in main.c.
Directory tree:
Project name
+ Core
| + ...
+ Drivers
| + ...
+ Libs
| + someLib
| | + Inc
| | | + someLib.h or hpp
| | + Src
| | + someLib.c or cpp
| + ...
+ Program
| + Inc
| | + cppmain.h
| | + ...
| + Src
| + cppmain.cpp
| + ...
+ ...
You will have to add Program/Inc and any Lib/Inc folder to the include path.
The changes to main.c then look like this:
...
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "cppmain.h" // this goes in user includes
/* USER CODE END Includes */
...
/* USER CODE BEGIN 2 */
cppMain(); // this goes before the main loop
// anything after this point will never be reaced
// when you create a main loop inside cppMain()
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
...
Inside the cppmain.h file I usually #include "main.h" to get all the STM32 HAL stuff and declare all hardware resource handles as extern (e.g. extern UART_HandleTypeDef huart1;)
The full cppmain.h file:
/** #file cppmain.h
*
* #author some_author
* #date some_date
*/
#ifndef PROGRAM_INC_CPPMAIN_H_
#define PROGRAM_INC_CPPMAIN_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "main.h"
void cppMain(void);
#ifdef __cplusplus
}
#endif
#endif /* PROGRAM_INC_CPPMAIN_H_ */
Some random cppmain.cpp file:
/** #file cppmain.cpp
*
* #author some_author
* #date some_date
*/
#include "cppmain.h"
#include "pins.h"
// pins is useful when you connect some things to a dev board
// and want to have a quick reference where you put stuff
// this just includes things like (for STM32F103xB "blue pill" in this case)
// #define LED_PIN_PORT GPIOC
// #define LED_PIN_PIN GPIO_PIN_13
// #define LED_PIN LED_PIN_PORT, LED_PIN_PIN
extern UART_HandleTypeDef huart1;
int some_variable = 0;
void foo(int input){
// do something
}
void cppMain(){
// do stuff
// main loop
while(1){
// do stuff regularly
}
}
In my Lib folder I usually link to libraries I want to change for all projects while working on them: right click on Libs -> New -> Folder -> Advanced >> -> Link to alternate location.
Note that this will link to an absolute path on your system and you can't simply import your project on a different system this way.
If you work in a team or across different devices you might want to solve this a different way.
I am using STM32CubeIDE version 1.8, it can let you add include folder directly from the project menu -> Add/remove include path:
To add source folder, you can create source folder from the project menu -> New -> Source Folder:
If you want to add include and source folders manually:
Project Properties-> C/C++ General->Paths and Symbols:
Select Includes tab to add header folder
Select Source Location to add source folder

Extern C/C++ confusion in ndk - Syntax error Eclipse

I wish to run a C Code in android for which I am using android ndk. I also need to add some libraries. While building these libraries, I am getting errors because of the extern statements in the header files. Eclipse IDE shows syntax errors. I also unchecked everything at Project-->Properties--> C/C++ Code Analysis.
Similar example is shown here. How to resolve this?
#ifdef __cplusplus
extern "C" {
#endif