I’m having the following problem using Digi ESP for NET+OS 7.5.2.
Under the IDE, I’ve got different project (Project 1, Project 2, …) using NET+OS 7.5.2. These projects have their own files and build fine.
However, I would like to include external common file into these projects (Eg: MyFile.c and MyFile.h). These files have to be shared between the Project_1 and Project_2. Instead of copying these files in each project, I linked them from each project.
For this I do the following:
- in the properties of each project, I add the include path of external files (Eg: C:\ExternalFiles)
- in the IDE project explorer, I click right on the project name, then select New / Folder. In the ‘New folder’ window opened, I click ‘Advanced’, check the box ‘Link to folder in the file system’ and browse to the folder having my external files (C:\ExternalFiles). Then click ‘Finish’.
At this point, in the IDE project explorer I can see the new folder ‘ExternalFiles’ shortcut included in my Project_1. Clicking on it opens the contents of the folder and I can see my external files (MyFiles.c and MyFiles.h).
But from this point, when I try to build my project (without making any call to any function in these external files), I get the following errors:
**** Build of configuration Debug for project Project_1 ****
make -k -s all
Building file: /cygdrive/C/ExternalFiles/MyFile.c
Invoking: C++ Compiler
/usr/lib/gcc/arm-elf/4.2.0/…/…/…/…/arm-elf/lib/crt0.o: In function start': ../../../../../../gcc-4.2.0-20070316/newlib/libc/sys/arm/crt0.S:(.text+0xec): undefined reference to main’
collect2: ld returned 1 exit status
make: *** [ExternalFiles/MyFile.o] Error 1
make: Target `all’ not remade because of errors.
For test, the MyFile.c has a very simple function:
unsigned int MyAdd(void)
{
unsigned int a=1, b=3;
return (a+b);
}
The ‘MyAdd’ function is not called from Project_1.
Can somebody explain me what I am doing wrong?
As soon as I delete this ExternalFiles folder from Project_1, I can build successfully.
There is a way to make it work by linking MyFiles.c instead of the folder ExternalFiles. But this way mix MyFiles.c with the other files of the project. I would like to have external files in their own folder.
Try the following, my results were more successful.
R click on project name
Click new file
Click advanced
Click link to file in file system
Click browse
Select your file
Click open
Click finish
You do NOT see the directory. Instead you see the link to the file. This method compiles cleanly whether or not you reference a function in the file in the external directory
Thanks for your reply.
I saw this solution. Despite the external files are mixed (in project navigator) with project files, the main problem is I can’t add all the files in one go. My example was using only one file, but for development I have up to 50 files. I don’t see myself doing this operation 50 times for each project.
Is there a way to resolve the error I’m having by modifying the makefile?
I would compile my external source files as a library (using a make command in pre-build steps).
However, I’m trying to add a library into my project. Although I add the library file (.a) and patch in “Project properties / C/C++ build / Settings / Tool Settings / Linker / Libraries” the linker keep returning the following error:
This is a level of "funkyness that is inherent in the gnu linker that caught me off guard. Please understand that this is how the gnu linker works.
“The -l option is used to add libraries to your program. The –l option is a shortcut for linking a library, because you can always just list the library on the command line (like “gcc hello.o mylib.a”). The benefit of the -l option is that you don’t need to know where the library is. This is used for the standard libraries, and in fact, gcc will automatically add -lc to whatever you type in order to get the standard C library (libc.a). Note that with the -l option, you only need to specify part of the library name. gcc assumes that the library name starts with “lib” and ends in “.a”, so -lfoo would refer to libfoo.a and would be found wherever the standard libraries are kept.”
Thanks a lot for this.
The linker now find MyLibrary. However, when I call the library functions ‘MyAdd’ from my project, the linker can’t find the function (undefined reference to ‘MyAdd’).
To create my library, I use DIGI ESP. In the project explorer, I create a new project / C project / Static Library / Empty Project. I add my .c and .h files, and click build. The libMyLibrary.a is correctly built BUT for X86 and not ARM.
How can I set my library project to build for arm and not x86?
Ok, first statement. There is NO official wizard for building libraries from within Digi ESP for NET+OS. There are also no plans for doing so. The only alternative path you have is to build your libraries from the command (make your own make files et al) and then include same into your ESP builds.
That said, here is something you can try that might get you where you want to go, that is where you are currently getting X86 libraries, getting ARM/NET+OS libraries.
Go to File > New > Project… to open the New Project wizard.
Select the check box called Show All Wizards to display extra options on the tree above this control.
Then select the item C Project located inside the C category and click Next.
(If a dialog asking you to enable some required activities appears, click OK)
Enter your project name, for example myProject, select Static Library > Empty Project from the Project type list and Cygwin GCC from the Toolchains list.
(picture was here but was lost)
Click Next to continue.
In the following page, click on the Advanced settings… button, it will open the Properties dialog to be configured for the future project.
Go to C/C++ Build > Settings > Tool Settings:
• Select GCC Assembler and edit the Command text box: type arm-elf-as (instead of as)
• Select GCC Archiver and edit the Command text box: type arm-elf-ar (instead of ar)
• Select Cygwin C Compiler and edit the Command text box: type arm-elf-gcc (instead of gcc)
Important Note:
(You have to do these changes for both Debug and Release configurations)
Click OK to apply and close the Properties dialog.
Click Finish to create the project.
Once the project is created you can add the source files inside. But you might need to edit the Includes for it, to do it just open the Properties of the project, go to C/C++ Build > Settings > Cygwin C Compiler > Directories and add the paths you need (you can have a look to the available NETOS include paths going to a NET+OS property page of a NET+OS project, inside the Includes tab)
Once everything is properly configured, you can build the project. The result of the project (libmyProject.a for our example) will be inside Debug or Release folder, depending on the configuration you build.
So this method has you replacing the std X86 tools chains (as, ar, gcc) with the ARM tool chains (arm-elf-as, arm-elf-ar, arm-elf-gcc). And remember you must do this for both debug and release.