Selecting a language for the portable library

I want to write a library that will be dynamically linked to other programs running on modern operating systems such as Windows, Linux and OS / X (i.e. it will be deployed as a module .dll or .so ).

What is the most appropriate language in this case? Should I stick to plain C? Or is C ++ ok too?

+4
c ++ c portability multiplatform
Jun 22 '09 at 0:56
source share
5 answers

You can use C or C ++ for implementation, but I would recommend defining the interface in pure C. It will be much easier to integrate.

+14
Jun 22 '09 at 0:58
source share

The difficulty with creating a C ++ library distributed in binary form is that your clients, users of the library, are usually forced to use the same C ++ compiler when creating the library. This can be problematic if you want to keep abreast of events, but they don’t, or if they want to keep abreast of events, but you don’t. If you are dealing with a source, this is less of a problem if your C ++ is portable enough to allow it to be used by all the compilers that your clients use.

If the code can be used with C, I would probably write code for the C interface. Alternative, provide two interfaces - a native C ++ interface and a C interface. But it is more than just a C interface. On the other hand, there may be advantages of a C ++ interface (possibly using STL iterators, etc.), and this may affect your decision.

+2
Jun 22 '09 at 1:13
source share

I would also say that C is the lowest common denominator. You always have the opportunity to write a C ++ shell in the main library if it integrates better with the calling application.

+1
Jun 22 '09 at 1:01
source share

I would say that C is the most predictably portable, but C ++ is doable.

0
Jun 22 '09 at 0:58
source share

Consider the Least Common Denominator Ratio and have your library consumers make the decisions that are best for them. The extern c construct is probably still confusing for some people, and you want your library to go far and reach the widest audience. Definitely make the interfaces clean c. C ++ is great if you avoid some darker corners (like STL). C is the most portable panel. Creating libraries for all available platforms is not a small feat, so be sure to take a look at some tips here. You may also consider using autoconf, etc.

0
Jun 22 '09 at 1:11
source share



All Articles