CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

header and source files linking

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
z3ngew



Joined: 20 Apr 2013
Posts: 50

View user's profile Send private message

header and source files linking
PostPosted: Tue Jul 09, 2013 5:37 am     Reply with quote

Hello everyone,
I have a question, i want to make my own code library but, theres a problem in the linking of the compiler.

The library is composed of 2 files ( header file.h and source file.c)
in the header file i am putting the declaration of my functions and global variables and in the source file i am putting the definition of functions and global variables.

but the compiler is not linking, and complaining (function used but not defined) any help please!

for example i have a file mylib.h
Code:
#ifndef mylib_h
#define mylib_h

int myfunction();
#endif


and the c file is mylib.c
Code:
#inlude "mylib.h"
int myfuction(void)
{
      .......
}


in the main function
Code:
#include <device.h>
#include"mylib.h"
void main(void)
{
     int a = myfunction();
}


Thanks in advance,
z3ngew
Ttelmah



Joined: 11 Mar 2010
Posts: 19348

View user's profile Send private message

PostPosted: Tue Jul 09, 2013 6:47 am     Reply with quote

Er. Well mylib.h, does not include mylib.c. You have mylib.c, including mylib.h, not the other way round....
z3ngew



Joined: 20 Apr 2013
Posts: 50

View user's profile Send private message

PostPosted: Tue Jul 09, 2013 7:24 am     Reply with quote

you are correct, but please take a look at the following link:
http://web.cs.swarthmore.edu/~newhall/unixhelp/howto_C_libraries.html

Thanks in advance,
z3ngew
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Tue Jul 09, 2013 10:14 am     Reply with quote

z3ngew wrote:
you are correct, but please take a look at the following link:
http://web.cs.swarthmore.edu/~newhall/unixhelp/howto_C_libraries.html


You are also correct, but CCS C doesn't quite work that way. Just quoting "standard" usage is not particularly helpful here. CCS sort of works that way, but mulitple compilation units such as you are trying to use, are a relatively recent addition to CCS which is essentially a single unit compiler. Also they've not worked well for many releases. I am not at all sure what the status of the current compiler is for this.

From this you might think that Multiple compilation units are not popular amongst CCS users. You would be right. One issue is that its rare that its required as most PICs have such limited resources and are so varied that its not practical to have truly common reusable library code as is the expected norm with most other C applications. You cannot write and separately compile source code into object code that can then be linked into any project. It has to be compiled from source almost every time.

In CCS C its not enough to just include the headers in your source. You must include all the relevant source files in your project. See "Multiple Compilation Units" in the compiler help for details.
Ttelmah



Joined: 11 Mar 2010
Posts: 19348

View user's profile Send private message

PostPosted: Tue Jul 09, 2013 2:54 pm     Reply with quote

Even on a compiler that as standard used multiple libraries, just the header file won't do. You have to tell the compiler to include the library object at the final link stage, and the library would have to be compiled to have the functions as exportable objects.
So what you are doing, would not work with any compiler, not just CCS....

You can do it this way with CCS now, but you then need to compile the library separately, include the lines in the library to say that the function is to be exported, and include the library in the link phase.

Best Wishes
z3ngew



Joined: 20 Apr 2013
Posts: 50

View user's profile Send private message

PostPosted: Tue Jul 09, 2013 5:12 pm     Reply with quote

Many thanks my friends , Very Happy
Sincerely
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group