Meme Game server Development Diary (iv) scons compilation tools, C and C + + mixed use

Source: Internet
Author: User

There was a problem with compiling python so today--linking the other C libraries to the same so--and trying to find the method in the morning, has been updated to the second section of this series.


Organized a list of projects, planning to use SCons management.

SCons, after all, is a new build tool, certainly a lot more progress than makefile, at least more clearly studious, less dizzy trick. But compared to other advanced tools such as CMake, it is not clear that the pros and cons.

This example is too simple to write, the normal use of env, you can unify parameters, simplified writing.

Example:

Obj = Object ("test.c", cpppath=["xxx"], cflags=["-G"]) Obj2 = Object ("main.cc", cpppath=["xxx"], cflags=["-G", "-std=c++ "]) Program (" Out_exe ", [obj, Obj2], libs=[" DL "], linkflags=["-pthread "])


Note that this example mixed with C source and CPP source code, SCons will use GCC and g++ respectively processing.

It is worth saying that the code part of the pure C language needs to be completely wrapped up with the following code.

#ifdef __cplusplus

extern "C" {

#endif

C code

#ifdef __cplusplus

}

#endif


mixed with C and CPP to write the reason is: with DLFCN library operation so, obviously C language will be more convenient, C language void* type, with a certain dynamic language characteristics, very easy to use, conversion is also basic will not be reported warning. The same code with g++ difficult to compile the past, to rewrite the law.

Python's source code is also written in C, with C calls relatively easy.

However, it is intended that the network library with Raknet,raknet is a large library written using the CPP feature.

So it's hard to use C and CPP, the code for Python and so is C-style, and most of the underlying logic and network parts are in C + +.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Meme Game server Development Diary (iv) scons compilation tools, C and C + + mixed use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.