Writing cross-platform C++ Code (Windows, Linux and Mac OSX)

前端 未结 5 1212
予麋鹿
予麋鹿 2021-01-29 19:48

This is my first-attempt at writing anything even slightly complicated in C++, I\'m attempting to build a shared library that I can interface with from Objective-C, and .NET app

5条回答
  •  闹比i
    闹比i (楼主)
    2021-01-29 20:09

    instead of repeating yourself and writing the same #ifdef .... lines again, again, and again, you're maybe better of declaring the probe() method in a header, and providing three different source files, one for each platform. This also has the benefit that if you add a platform you do not have to modify all of your existing sources, but just add new files. Use your build system to select the appropriate source file.

    Example structure:

    include/probe.h
    src/arch/win32/probe.cpp
    src/arch/linux/probe.cpp
    src/arch/mac/probe.cpp
    

    The warning is because probe() doesn't return a value. In other words, none of the three #ifdefs matches.

提交回复
热议问题