i have written a simple UART code, my project is entirely depends upon the serial comunnication.
i have to control 4 to 5 stepper motor and sensor, for which lot of subroutines r to be written, i wanted to make small library which are classified into motor,uart,sensor codes .
now i have written a simple test code for my project, it is working fine when i write all the code in one C file.
when i am tring to modularized the code compiler shows 0 errors but 10 warnings.
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL SYMBOL: SYSTEM_INIT MODULE: D:\SWAPNIL_PROJECT\S.O.A.M_30112010\CODE\VERSION2\SOAM_12112010\K >> EIL2\TEST1.OBJ (TEST1) *** WARNING L1: UNRESOLVED EXTERNAL SYMBOL SYMBOL: PORT_IO_INIT MODULE: D:\SWAPNIL_PROJECT\S.O.A.M_30112010\CODE\VERSION2\SOAM_12112010\K >> EIL2\TEST1.OBJ (TEST1) *** WARNING L1: UNRESOLVED EXTERNAL SYMBOL SYMBOL: _UART1_TX MODULE: D:\SWAPNIL_PROJECT\S.O.A.M_30112010\CODE\VERSION2\SOAM_12112010\K >> EIL2\TEST1.OBJ (TEST1) *** WARNING L1: UNRESOLVED EXTERNAL SYMBOL SYMBOL: UART1_INIT MODULE: D:\SWAPNIL_PROJECT\S.O.A.M_30112010\CODE\VERSION2\SOAM_12112010\K >> EIL2\TEST1.OBJ (TEST1) *** WARNING L1: UNRESOLVED EXTERNAL SYMBOL SYMBOL: _DELAY MODULE: D:\SWAPNIL_PROJECT\S.O.A.M_30112010\CODE\VERSION2\SOAM_12112010\K >> EIL2\TEST1.OBJ (TEST1) *** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL SYMBOL: SYSTEM_INIT MODULE: D:\SWAPNIL_PROJECT\S.O.A.M_30112010\CODE\VERSION2\SOAM_12112010\K >> EIL2\TEST1.OBJ (TEST1) ADDRESS: 0090H *** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL SYMBOL: UART1_INIT MODULE: D:\SWAPNIL_PROJECT\S.O.A.M_30112010\CODE\VERSION2\SOAM_12112010\K >> EIL2\TEST1.OBJ (TEST1) ADDRESS: 0093H *** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL SYMBOL: PORT_IO_INIT MODULE: D:\SWAPNIL_PROJECT\S.O.A.M_30112010\CODE\VERSION2\SOAM_12112010\K >> EIL2\TEST1.OBJ (TEST1) ADDRESS: 0096H BL51 BANKED LINKER/LOCATER V6.11 11/15/2010 17:19:25 PAGE 3 *** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL SYMBOL: _DELAY MODULE: D:\SWAPNIL_PROJECT\S.O.A.M_30112010\CODE\VERSION2\SOAM_12112010\K >> EIL2\TEST1.OBJ (TEST1) ADDRESS: 00A0H *** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL SYMBOL: _UART1_TX MODULE: D:\SWAPNIL_PROJECT\S.O.A.M_30112010\CODE\VERSION2\SOAM_12112010\K >> EIL2\TEST1.OBJ (TEST1) ADDRESS: 00ADH Program Size: data=17.0 xdata=0 code=198 LINK/LOCATE RUN COMPLETE. 10 WARNING(S), 0 ERROR(S)
please help me understand where i am going wrong
The errors are Linker errors relating to missing definitions.
The source code is not relevant here - the problem is in the inputs provided (or not provided) to the Linker.
I'm not really clear on why you want to use libraries for this but, if you do, it means you will have to break your project up:
You will need a separate project to create each library;
Then you will also need an "application" project which uses these libraries.
well i first wanted to modularised my source code for easy maintenance, and the code above is just the hardware test code, the project is quite a big one.
but when i do the procedure which i have done above, i come up with same problem i.e. 0 errors and hundreds of warning.
when i compile and start debugging the cursor stops at the function which is in other files.
it seems like it is linker error, as u mentioned above.
note: i am using Silab IDE 3.10 to built the code and for emulating it. this problem comes with this ide, when i use uvision 3 & create a *.lib there is 0 error and 0 warning, but i don't know how to download my code in controller c8051f340 and emulate it.
PLease help me, if u need more information let me know.
There is no need to break a single project into libraries to do that.
Libraries are only really useful when identical code needs to be shared between multiple projects without sharing the source.
You don't necessarily have to build library files just to share common source code - you can just use a common group of source files.
For instructions on splitting one huge .c file into "modules", see your new thread: http://www.keil.com/forum/17893
When multiple projects shares the same source code, I normally keep that code in a subdirectory.
So when checking out the project source code from a source code repository, I both check out the project-specific code, and the common code.
The advantage with building the full project from source code instead of having part of it linked with a library, is that the debugger will have access to all source - I can single-step into the shared code without problems.
Next thing is that if I do feel the common code lacks a feature, I can update that code with additional functions and directly test within the project. Obviously, shared code must be handled carefully, i.e. I can't redefine the meaning of a variable or function since that would break all other projects that are using the same shared code.
If a project do make changes to common code, then I check in these changes and make a new source code "tag" for the shared code. So when building other projects, I can decide to either check out the old version of the shared code, or upgrade the other projects to use a newer version of the shared code.
Binary libraries are best when: - the library is huge, making the build time extremely long. But this is seldom a problem with modern computers. Few developers have projects that takes 10 minutes or more for a full build. - the library is shipped to other people, and you do not want them to have access to the source code (might contain proprietary, maybe patented/trade secret algorithsms, or maybe you don't want to give support when they change things and breaks the library).
A big problem with a binary library is that they often fail if you switch compiler vendor or sometimes even compiler version. And you often need several libraries, depending on what compiler options you have used - i.e. a debug build, a release build, a unicode build, a "strict" build, ...
So in the end, there is normally very little reasons for building own libraries unless it's a school assignment. If you do work for a company that does sell libraries, then that company must have (or at least have had) other people who have done this before.