How do I add preprocessor defines in Code Composer Studio 4? - c-preprocessor

I have an external text file with some preprocessor defines. How can I integrate them in my CCS project?

For CCSv5
Project -> properties -> C/C++ General -> Path and Symbols
Under the tap Symbols you can put your defines
One thing to note: remember to press the "Show advanced setting" in the bottom left corner, or else the C/C++ General does not show up

You could copy/past in compiler settings : Menu Build properties > compiler > preprocessor > defines.

For CCSv8
Project -> properties -> Build -> MSP430 Compiler -> Predefined Symbols

Related

Eclipse CDT MinGW toolchain: how to link with a library that does not begin with lib prefix?

I have problems with linking to a library called xyz.a in my Eclipse CDT MinGW project. Eclipse projects cannot find this library unless I rename it to libxyz.a.
I have added:
library path to project via Properties/C C++ General/Paths and Symbols/Library Paths.
library name to project via Properties/C C++ General/Paths and Symbols/Libraries. Library name I specified here is xyz, so it's without extesion. What should I specify here in order to successfully include xyz.a without having to rename it to libxyz.a?
Some info I found online:
How do I specify the libraries to be searched by the linker?
MinGW supports libraries named according to the "<name>.lib" and "<name>.dll" conventions, in addition to the normal "lib<name>.a" convention common on *nix systems. To include libraries named according to any of these conventions, simply add an associated "-l<name>" specification to the compiler command, ensuring it is placed after the name of the module in which the reference appears.
Note that, if the library is not found in any of the default library search paths, you may also need to insert an appropriate "-L<dir>" switch to specify its location; (it is recommended that you place the "-L<dir>" switch before the "-l<name>" specification which requires it).
Also note that the library names "lib<name>.a" and "lib<name>.lib" are not equivalent; if you have a library named according to the aberrant "lib<name>.lib" convention, it will not be found by an "-l<name>" specification -- if you cannot rename the library, you must use the form "-llib<name>" instead.
You can link a library called oddname - where oddname includes any file-extension - in Eclipse CDT like this:
Navigate in the project Properties -> C/C++ Build -> Settings
-> Tool Settings -> GCC C++ Linker -> Libraries.
In Libraries(-l) panel add :oddname
If necessary, in the Library search path(-L) panel add the path to
oddname
OK out
This setting will add the option -l:oddname to the generated GCC link
command. -l:filename is the form of the -l option signifying that
the conventional lib prefix and the {.so|.a} extension are not implied and that
filename is the actual filename of the library to be linked. Here is the documentation
The simplest option is to just add the library to the command line of GCC. To do this with CDT add the library (whatever name it is) to the Other object (under Project settings -> C/C++ Build -> GCC C Linker -> Miscellaneous)
Here is a screenshot where I added a library with the file name badname.a to the command line of GCC.
When the build runs, this is the resultant command line:
Invoking: GCC C Linker
gcc -o "SO" ./src/SO.o /home/me/workspace/SO/badname.a
Note: the disadvantage of the above solution is the whole library is included, not just the objects within it that are referenced. You can alternatively add any linker flags you want by adding them to the Linker flags box in the same dialog.

Append version number to output file for C application in Eclipse

I have a version.h header file where I have the version of my application defined:
#define VERSION 0x0100
I would like to add it as a suffix to the output file. So instead of having myapp.elf I would like to have myapp_0100.elf. Is there a way to use symbols in the compilation options?
You can do the opposite. Define a variable in Eclipse and use it when compiling.
Go to the Project Properties-> C/C++ Build -> Build variables
Define a new variable blah with value 0100. Then in the build settings, depending on your project type you can pass the -DVERSION=${blah} to the compiler. It will define the symbol called VERSION with the value given.
Now in Project Properties-> C/C++ Build -> Setting choose the Build Artifact tab. In the artifact name you can set myapp_${blah}.elf. Again, if your project is non-CDT managed, you can pass this variable to the makefile in order it to process it instead.

MinGW and Eclipse on Windows - generating assembly output

I recently installed MinGW to play around with (non-AVR-specific) C development on Windows. I'd like to see the assembly generated by GCC along with the .o file; I've played around with changing some of the command line flags under "C/C++ build" and "Properties" for the test project I'm using, but I can't seem to alter the build behavior. Is there a straightforward way to do this? Thanks!
The way to do it is to add -Wa,-aln=output.s to the "Command" box under Properties > C/C++ Build > Settings > Tool Settings > GCC C Compiler.
Bitrex was on the right path but a better way to do is under "Properties > C/C++ Build > Settings > Tool Settings > GCC C Compiler > Miscellaneous", append -Wa,-aln='${CWD}\\${InputFileBaseName}.cod' (take notice of the single quotes) to the end of "Other flags". This will not only generate the assembly, but seperate them by the source file.
With Bitrex's way, if you have multiple source files, each assembly output will be overwritten by the next source file, because he forces them all to be named "output.s".
Note: Use "GCC C++ Compiler" if your compiling C++ code.

Eclipse C/C++ (CDT) import files into project - header file not found - include path

I am trying to import files into an Eclipse C project and compile it. The build process cannot find the local header files. The header files are located in the src directory. How can I edit the include path in eclipse? If I were doing it manually I could specify the -I option in gcc.
Building file: ../src/averaging.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/averaging.d" -MT"src/averaging.d" -o"src/averaging.o" "../src/averaging.c"
../src/averaging.c:2:23: fatal error: averaging.h: No such file or directory
compilation terminated.
make: *** [src/averaging.o] Error 1
Right click on the project and select properties.
Select C/C++ General -> Path and Symbols.
Select Includes tab.
In Languages list, select 'GNU C' or whatever C compiler tool chain you use.
Press 'Add...' button and add the directory for the include files.
Close Properties window and rebuild. You should see new path being used as -I in build process.
None of what I have found so far helped, among other things adding the include path in the following places did not work for me:
Project -> Properties -> C/C++General -> Paths and Symbols -> Includes tab -> GCC C
Project -> Properties -> C/C++General -> Paths and Symbols -> Includes tab -> GCC C++
Project -> Properties -> C/C++build -> Settings: Tool settings tab -> GCC C++ Compiler -> includes
Project -> Properties -> C/C++build -> Settings: Tool settings tab -> GCC C Compiler -> includes
However, adding the include path to:
Project -> properties -> C/C++General -> Paths and Symbols -> Includes
tab -> Assembly
while checking 'add to all languages' did work.
Strangely enough this last option does all the above - why they do not work on their own is not really clear to me.
This is assuming that you do not use makefile. If you do then you can forget about changes as listed above. Eclipse will find automagically where all needed input is by analyzing compiler logs. I thought this is magic but it works the following way:
Build All from project menu - even if that succeeded it may leave some of your files marked with 'faults' because of unknown symbols and such so you have to go for step two:
update the index: from project window you right click and chose "Properties -> Index -> Rebuild. If the project is big you will see progress in lower right corner of eclipse window.
I think above process can be done in different ways and eclipse can do it all by itself too but for large projects I found manual handling as described above less distracting.
Alt + Enter for opening Properties.
Open C/C++ General -> Paths and Symbols -> Includes -> Add...
Note that sometimes you need to choose "Is a workspace path" (ex: for linked folder).
1.Click on your source folder
2.Select 'New'
3.Next select 'Header File'
4.Give a proper name with ".h" extension(For example : header.h)
5.Then select 'Finish'
6.Then create your function
7.Save your "header.h" file
8.Then select 'Project' from the top of the console
9.Select 'Build All'
10.Then open your ".c" file
11.Write #include"header(see step 4).h" to use the header file
12.Follow step 7 to 9
13.Then click on 'Run' from the top of the console

C programming in Visual Studio 2008

Do you know if it's possible to programm c (not c++) in Visual Studio 2008? If yes then how? I haven't found any component for that.
Regards.
Just save the file with .c extension instead of .cpp and it will compile as C instead of C++. To be extra cautious, you can go to the project settings, under "Project -> Properties -> Configuration Properties -> C/C++ -> Advanced", make sure that "Compile As" says "Compile as C code (/TC)".
As long as your source file has the .c extension, Microsoft C++ compiler will compile in C-mode.
In addition, the /Tc<source filename> switch can be used to force compilation of a specific file in C mode, and the /TC switch can be used to force C mode for all files. For C++, it's /Tp and /TP respectively.
You can specify any compiler you'd like in VisualStudio; therefore, if there's a specific C compiler you'd like to use, it will handle it.
If you want to make a .c program in Visual Studio 2008:
Goto>>File>>New>>Project
Choose "Visual C++" in the left column, then in the right column, select "Win 32 Console Application".
Write file name as:
"Any_Name.c"
Here you can now create a C program:
Create source file
To compile, press ctrl+shift+B
To run, press F5
It does not work because C++ precompiled headers, so the solution is select project-properties-c/c++-precompiled headers
Then select Not Using Precompiled Headers

Resources