I have been asked to provide a C-library of my code (which I have written in a high-level language). I will hire a programmer to implement my code in C. I would like a short introduction to what a "C-library" means before I start this process.

  1. Is it correct that I can provide a C-library and that the people who use it will not be able to see the actual source code?
  2. I understand that the library will inlude .h-files which determine how the people that I give the code to will interact with the library. Can I have just one of these files so that the internal structure is hidden?
  3. In this situation, I assume that the library should be dynamically linked. Why is that?
  • 1
    Can you tell us at least what language you are using? – Kilian Foth Feb 5 '15 at 11:04
  • I am currently using Matlab – StevieStevie Feb 5 '15 at 11:07
  • 3
    According to google you can call matlab functions from C, so all you need would be a thin wrapper between C and your library. That would make it unnecessary to reimplement it all. – Philipp Feb 5 '15 at 11:10
  • 1
    The problem is that the end user (which will be the customer to the party requesting the code) would need the "MCR" in that case which is like 500 MB or something. – StevieStevie Feb 5 '15 at 11:12
  1. Yes
  2. Yes
  3. It doesn't have to be dynamically linked.

In detail: When creating a library (doesn't have to be in C, but I assume this means it needs to expose its functionality in the form of exported C functions) then the source code is turned into the equivalent machine instructions. While a skilled hacker could turn this machine code back into a higher level language, its really awkward and the resulting decompilation is really difficult for a human to understand. So you're pretty much safe from anyone stealing your algorithms, unless they're really worth the effort.

In order to use a library like this, you need a way to tell programs that link with the lib what is inside it, this is typically done with a header file. A single header containing only those exported functions is fine. The only reason people use multiple headers is because they don't want the trouble of maintaining duplicates and so simply ship the headers used in development.

The choice of dynamic or static is up to you. A dynamic library can be replaced with a newer version easily. This is the most common reason to ship in this format.

  • Thanks. Can someone that I send this c-library to be able to use it to create application for e.g. android, iOS and windows? – StevieStevie Feb 5 '15 at 11:27
  • And also. It is a quite complex solution so it is not like they can just steal this one valuable line of code. But the complete code may be valuable though.. – StevieStevie Feb 5 '15 at 13:20
  • 1
    @StevieStevie no, a C compiler will turn your source code into machine instructions specific to the platform and/or CPU. So a lib compiled for ARM CPUs won't work on x86 CPUs. Similarly, one that uses existing library functions for Linux or Android won't work on Windows or iOS. However, if you write your code in a cross-platform manner (quite easy if you're not doing things like GUIs) then you should be able to compile it for each target platform, so iOS devs would use the iOS version. – gbjbaanb Feb 5 '15 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.