Set up CMakeLists to not change the include statem

2019-08-27 17:57发布

问题:

From a previous question a new one have arisen. I want to include 2 native TFS project libraries stored in two different folders, dependant from each other in my Android Studio project (stored in another folder). If i not specify "../my_lib_path/libFile.h" instead of simply the "libFile.h" i get the error the file is not found. But i dont want to change all includes since it is a TFS project and there are lots of file contained in the libraries!

Your help is highly appreciated!

回答1:

Add the given directories to those the compiler uses to search for include files. Relative paths are interpreted as relative to the current source directory. So you have to specify "../my_lib_path/libFile.h", that means you need to change all includes, otherwise it will not work.



回答2:

@Andy Li-MSFT is absolutely right! Though what worked for me in a similar project now was to set a different relative CMakeLists.txt path in the app .gradle file outside the specific Android Studio Project directory:

externalNativeBuild {
        cmake {
            path "../../whatever_path/my_C_files/CMakeLists.txt"
        }
    }

After that i was able to compile my C sources flawlessly without changing the include paths of the C project!