链接C ++ / CMake项目中的子目录

时间:2015-12-05 17:20:17

标签: c++ cmake

我的QT项目中有以下文件夹hieararchy,我需要在其他文件夹中使用Utility的某些类...例如ImageProcessing

enter image description here

实用程序的CMAKE文件:

file(GLOB Utilities_Files *.cpp *.h *.hpp)

# add component
add_library(Utilities ${Utilities_Files})

find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(Utilities ${OpenCV_LIBRARIES})

ImageProcessing的CMAKE文件:

file(GLOB ImageProcessing_FILES *.cpp *.h *.hpp)

# add component
add_library(ImageProcessing ${ImageProcessing_FILES})

include_directories(../Utilities)
target_link_libraries(ImageProcessing Utilities)


find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(ImageProcessing ${OpenCV_LIBRARIES})

我成功地将StringUtils.h中的Utilities加入Drawings.cpp ImageProcessing {/ 1}}中:{/ 1>

#include "StringUtils. H"

但是当我尝试在Drawings.cpp中使用它时,如下所示:

#include "Drawings.h"
#include "StringUtils.h"
#include "opencv2/highgui/highgui.hpp"

Drawings::Drawings()
{
}

void Drawings::writeImageWindowsResultToDiskBasedOn(vector <Mat> imagesToTest, int windowLength, string pathOfImagesToWrite, vector < vector <int> > resultsForEachImagePerTile, int kNearestNeighbor, int percentageOfWhiteToConsiderIntrumentWindow)
{
    for (int index = 0; index < imagesToTest.size(); index ++)
    {
        Mat imageTest = imagesToTest[index];
        vector <int> resultsImagePerTile = resultsForEachImagePerTile[index];
        int indexOfTileForImage = 0;
        Mat binaryResultOfImageTest(imageTest.rows, imageTest.cols, CV_8UC1);
        for (int row = 0; row < imageTest.rows; row += windowLength)
            for (int col = 0; col < imageTest.cols; col += windowLength, indexOfTileForImage++)
            {
                // Setup a rectangle to define your region of interest
                cv::Rect window( col, row, min(windowLength, imageTest.cols - col), min(windowLength, imageTest.rows - row));
                cv::Mat tile = binaryResultOfImageTest(window);

                int valueOfPixel = (resultsImagePerTile[indexOfTileForImage] * 255) / 100 ;

                //This region should be set to valueOfPixel..
                tile.setTo(valueOfPixel);
            }

        stringstream imageName;
        imageName << pathOfImagesToWrite << "ImageResult" << index << "-k" << kNearestNeighbor << "-wl" << windowLength << ".png";
        imwrite(imageName.str(), binaryResultOfImageTest);

        int windowSize = 9;
        medianBlur ( binaryResultOfImageTest, binaryResultOfImageTest, windowSize);
        stringstream imageNameMedian;
        imageNameMedian << pathOfImagesToWrite << "ImageResult" << index << "-median" << windowSize << "-k" << kNearestNeighbor << "-wl" << windowLength << ".png";
        StringUtils::stringFormat("%sImageResult%d.png", pathOfImagesToWrite.c_str(), index);

       //.....

    }
}

编译器说:'StringUtils' has not been declared

以下是StringUtils的头文件:

#include "iostream"

using namespace std;

namespace Utilities {

class StringUtils
{
public:
    StringUtils();
    static string concat(string s1, string s2);
    static string stringFormat(const string fmt_str, ...);
    static bool hasSuffix(const string& s, const string& suffix);
};

#endif // STRINGUTILS_H
}

所以在我看来这个配置中缺少一些东西。你可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

您的StringUtils包含在Utilities命名空间中。您可以在cpp文件中使用using namespace Utilities;