How to compile some parts ?

General discussion on mikroC PRO for ARM.
Post Reply
Author
Message
orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

How to compile some parts ?

#1 Post by orpheedulogis » 20 Jul 2015 07:35

Hi all

Now I would like to do this: I want my project is readable but just for some parts, not all parts.
In fact I would like some functions could be used as I wrote them, without modifications.

Could you try to explain simply me how to do this, if possible ?

Thanks

User avatar
aleksa.jovanovic
Posts: 526
Joined: 30 Jun 2015 08:48

Re: How to compile some parts ?

#2 Post by aleksa.jovanovic » 20 Jul 2015 10:14

Hi,

I'm not really sure I understand what you mean.
Do you want to protect the source code, the HEX, or something else?

Best regards,
Aleksa.

orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

Re: How to compile some parts ?

#3 Post by orpheedulogis » 20 Jul 2015 13:51

Sorry for my bad english

Suppose you made , on one sheet of your project, special display functions like "Print_On_Two_Lines_With_Clock(char *DisplayString, char TimeDelay, char StringColor)" ...

Now, on main sheet, suppose you didn't want future programmer can modify display functions (as you do on Mikroc because I think we can't modifiy "TFT_Write_Text" function )

I would like to do so: my personnal code for some functions will be fixed although main code may be updated.

Is it more clear ?




Another thing I remember writing word "delay" here: there is a problem with delay function. if you write "Delay_ms(10)" it work but, as I needed variable delay ion some cases, I tried to do a delay function like this

Code: Select all

void SpecialDelayFunction(char Timems)
{
    char x1;
    for (x1=0;x1<=Timems,x1++) delay_ms(1);
}
it works ... but just for short delay !

aCkO
Posts: 1119
Joined: 14 Feb 2011 04:07
Location: Bar, Montenegro

Re: How to compile some parts ?

#4 Post by aCkO » 20 Jul 2015 15:15

orpheedulogis wrote:I would like to do so: my personnal code for some functions will be fixed although main code may be updated.

Is it more clear ?
Put all your private code in one or more source file. After compiling the project, for each source file the compiler will generate MCL file. These are compiled binaries. In your distribution version of the project, remove the private source files and add their compiled versions (*.mcl) in the Project Explorer window (Binaries).
orpheedulogis wrote:Another thing I remember writing word "delay" here: there is a problem with delay function. if you write "Delay_ms(10)" it work but, as I needed variable delay ion some cases, I tried to do a delay function like this

Code: Select all

void SpecialDelayFunction(char Timems)
{
    char x1;
    for (x1=0;x1<=Timems,x1++) delay_ms(1);
}
it works ... but just for short delay !
It will never work that way because you have to take into account the execution time of other instructions. However, you don't even have to do that since there is already built-in Vdelay_ms function which takes a variable as argument.

Regards

orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

Re: How to compile some parts ?

#5 Post by orpheedulogis » 20 Jul 2015 16:07

Thanks a lot

For Vdelay it will be OK 8)


For compiling I'm not sure :roll:

First I can't see "mcl" files but only "emcl". Are they the same ?

Second, could you confirm me:

- I make a new project with specific text sheets I want to be unmodifiable
- I compile them
- I move the result file in a global project (".emcl" file ?)
- add a new #include "FixedFunctions" in main file

Can you explain me very simply ?

Regards


Update:

I searched. perhaps I have to do like this (please confirm)

1) make a specific project with functions I want to protect, compiling project
2) copy emcl generated file in "C:\Program Files (x86)\mikroC PRO for ARM\Uses\ST M4" (I use STM32F407)
3) use my "old" project, removing sheets I want to be unreadable
4) import "emcl" file as library

Am I OK ?

aCkO
Posts: 1119
Joined: 14 Feb 2011 04:07
Location: Bar, Montenegro

Re: How to compile some parts ?

#6 Post by aCkO » 20 Jul 2015 16:51

To distribute your project you need to do the following:

1. Compile the original project
2. Duplicate your original project folder
3. Delete source files you want to hide (*.c)
4. Add compiled versions of the deleted source files to the project (*.emcl)

That's it.

Regards

orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

Re: How to compile some parts ?

#7 Post by orpheedulogis » 21 Jul 2015 11:48

Sorry :?

On Easymx pro board, with original STM32F107 processor

I made a very simple "project" -one sheet- with only one function to display a specific word, and one variable
(like "void DisplayHello(char ApparitionNumber)" )

Of course this function cannot work alone but it compile so I got an "emcl" file.


I copy this file in library folder, close mikroC so it can upadate and took an example project ("TFT_main")

problem: how can I tell to the example I have a new library (I can't see it !) so I can call "DisplayHello(10)" ?

I tried to put this emcl file directly in the project directory but it's the same problem: how to declare this library ?


---------------------------------------------------------------------------------------------

update

Please just confirm this is OK

I cancelled what I did before.

- I made a normal programmation (many sheets)
- I build the project to verify all is OK
- I removed files I didn't want to be modified ( "*.c" and "*.c.ini" files)

Doing this I can close , re-open MikroC, compile main without error message.
Is it so simple ?

aCkO
Posts: 1119
Joined: 14 Feb 2011 04:07
Location: Bar, Montenegro

Re: How to compile some parts ?

#8 Post by aCkO » 21 Jul 2015 14:01

orpheedulogis wrote:Sorry :?
update

Please just confirm this is OK

I cancelled what I did before.

- I made a normal programmation (many sheets)
- I build the project to verify all is OK
- I removed files I didn't want to be modified ( "*.c" and "*.c.ini" files)

Doing this I can close , re-open MikroC, compile main without error message.
Is it so simple ?
Yes, it is very simple. You just need to add binaries to your project. In the Project Explorer window right-click on "Binaries" -> "Add files to project..." and select the *.emcl files that contain the code you want to keep private.

Regards

orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

Re: How to compile some parts ?

#9 Post by orpheedulogis » 22 Jul 2015 07:14

OK

Thanks a lot

orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

Re: How to compile some parts ?

#10 Post by orpheedulogis » 31 Jul 2015 10:23

Now, another thing:


Suppose

1) in a "h" definition file, for example "Definition1.h"

Code: Select all

#ifndef PortDefinition
#define PortDefinition 
   sbit Led1 at GPIOA_ODR.B3;
#endif



2) In first project, main zone

Code: Select all

#include "Definition1.h"


void main()
{
     char x1;

     x1=Led1;  
}
3) now, in second project (who will give me "emcl" file) I need Led definition so I copied "Definition1.h" file in directory. In this project main will just have included files

Code: Select all

#include "Definition1.h"


void main()
{
   // nothing
}
4) Now, I get back to first project and added "emcl" file in directory

If I compile it gived me an error, telling Led1 as been redefined
I suppose that it's because compilator separe "emcl" declarations.

Is there a solution for this ?

aCkO
Posts: 1119
Joined: 14 Feb 2011 04:07
Location: Bar, Montenegro

Re: How to compile some parts ?

#11 Post by aCkO » 31 Jul 2015 14:11

It doesn't make sense to use emcl file with compiled main function because the other project will have its own main routine. The error you are receiving is because the sbit declaration is already part of the emcl. Also, emcl files are intended for libraries and it isn't wise to hardcode the pin declaration there. You should declare sbit as extern and the problem will be solved.

Regards

orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

Re: How to compile some parts ?

#12 Post by orpheedulogis » 02 Aug 2015 08:02

I understand :wink:

The problem I have is that I have now to find how I could extract some parts.

So I must modify my extracted parts before separating them. Next time I will prepare this differently.

Thanks

Post Reply

Return to “mikroC PRO for ARM General”