我想在android studio 中调用多个c++ 编写的.cpp 和.h文件,我在网上找了大多是说生成一个.cpp文件的,不知道怎么调用这些sourse code想请教一下?

解决方案 »

  1.   

    把所有的.h和.cpp文件都放到同一个工程中,   然后在需要的地方包含就行了.
    就像常用的  stdio.h   stdlib.h  这些头文件一样..如果你用的最新的android studio的话, 只需要配置 CMakeLists.txt //源文件目录指定
    aux_source_directory( src/main/cpp/dir1 DIR1_SRC)   //源路径dir1
    aux_source_directory( src/main/cpp/dir2  DIR2_SRC)  //源路径dir2  
    list( APPEND DIR2_SRC ${DIR1_SRC} )   //合并列表include_directories(src/main/cpp/dir1 src/main/cpp/dir2)   //头文目录指定add_library( # Sets the name of the library.
                 mylibname             # Sets the library as a shared library.
                 SHARED             # Provides a relative path to your source file(s).
                 # Associated headers in the same location as their source
                 # file are automatically included.
                 src/main/cpp/main.cpp ${DIR1_SRC})  //把刚刚指定的源文件列表加入到里面.
    特别注意:   这些修改后一定要执行刷新操作    Build --> Refresh Linked C++ Projects