After you create a library project in CCS, you have two options to use it in another application project. The first one is to link the files (.h and .lib generated file) directly from the library project location. The second option is copy-paste .h and .lib files in the application location.

I use to call the first one as ‘Development mode’ and the latter ‘Production mode’. In the first case your application uses the latest changes in your library project, so every time you build your app, the library is built too. This is useful  when you are developing the library, fixing bugs, adding new features, making tests and examples.

The ‘Production mode’ is useful when you don’t need to work within the library capabilities, but on an application that uses library’s functions instead. Because you have copy-pasted fixed version of files, development is focused on the application rather than generic functionalities provided by the library.

Below I will show the steps in configuring two projects that use a library, one in development mode and one in production mode.

Development mode

We will create a new project named ‘my_c_lib_test’

usingclib1

Then, in project properties window (Project properties > CCS Build > MSP430 Compiler > Include Options), we have to add include folder of the library project to include path.

Screenshot from 2015-12-30 08:39:14

Now, we have to link the generated .lib file, which is located in Debug folder of the library project. Actually, the name of the folder where the .lib file is located depends on the name of the build configuration of the library project. We go to Project properties > CCS Build > MSP430 Linker > File Search Path, and in the section ‘Include library file’ browse .lib file.

Screenshot from 2015-12-30 10:50:36

With the project configured, we can use now functions of the library in our main file. For example:

#include <msp430.h>
#include "misc.h"

/*
 * main.c
 */
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

    print_hex(27);
	
	return 0;
}

 

Production Mode:

For using the library in production mode, let’s create a project named ‘my_app_using_clib’

Screenshot from 2015-12-30 13:38:10

And now, create a folder named ‘include’ and inside it a folder named ‘clib’. In this folder is where .h files of the library should be copied.

Screenshot from 2015-12-30 13:44:44

This ‘include’ folder should be added to include path of the project in the same way as we did in development mode.

Screenshot from 2015-12-30 13:49:12

Now, .lib file in Debug folder of library project should be copied to the application folder, and then linked in project properties window.

usingcliblocallink

Finally, our main.c file could be like this

 

#include <msp430.h>
#include "clib/misc.h"

/*
 * main.c
 */
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

    print_hex(27);
	
	return 0;
}

Another option you have is to use the same project in two modes using build configurations (Debug and Release), one for each mode.

Feel free to comment, ask or suggest some changes.

Advertisements