简体   繁体   中英

CMake and wxWidgets 2.9.5

I'm attempting to write a packet sniffer and decided to use CMake to handle the build configuration since at some point I intend for it to be cross platform. It utilizes the Pcap (1.4) and wxWidgets (2.9.5) libraries and thus far I have been able to use CMake to generate build files for XCode 5.0.1 and Unix Makefiles.

Rather than install these libraries to system directories, I'm using static libraries (*.a) and bundling them with my executable for both portability and convenience since at this point it really only needs to run on OS X (so that my professor can compile it). My file structure looks like this:

project root
    build/
    src/
        main.cc
        CMakeLists.txt
        libpcap.a
        libwx_osx_cocoa_static.a

I compiled both Pcap and wxWidgets (specifically wxCocoa for the time being since it has an XCode project and would build the static library) on my machine.

CMakeLists.txt looks like this (I realize it isn't very robust, I just want it to work):

cmake_minimum_required (VERSION 2.6)
project (PacketCap)

add_executable(PacketCap main.cc)
target_link_libraries(PacketCap ${CMAKE_SOURCE_DIR}/libpcap.a)
target_link_libraries(PacketCap ${CMAKE_SOURCE_DIR}/libwx_osx_cocoa_static.a)

And main.cc:

#include <iostream>
#include "pcap.h"
#include <wx/string.h>

int main(int argc, const char * argv[]) {
    char *dev, errorbuf[PCAP_ERRBUF_SIZE];
    dev = pcap_lookupdev(errorbuf);
    if (!dev) {
        std::cout << errorbuf << std::endl;
        return -1;
    }
    std::cout << dev << std::endl;

    wxPuts(wxT("Import test"));

    return 0;
}

When I remove the wx import, it compiles and works as expected with pcap. However when I add the wx lines I get this error after running make:

fatal error: 'wx/string.h' file not found

Any suggestions on how to fix this so that I can import the wxWidgets libraries? I'm happy to provide any other relevant information!

Here is a minimal wxWidgets example:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.7)
PROJECT(wxTestbed)

FIND_PACKAGE(wxWidgets REQUIRED html adv core base net aui xrc qa richtext )
INCLUDE(${wxWidgets_USE_FILE})

ADD_EXECUTABLE(wxTestbed WIN32
    src/main.cpp)

TARGET_LINK_LIBRARIES(wxTestbed ${wxWidgets_LIBRARIES})

The header file can not be found because INCLUDE(${wxWidgets_USE_FILE}) is missing.

Take also a look at my minimal wxWidgets example: https://bitbucket.org/Vertexwahn/cmakedemos/src/a22a956e1e4b/wxTestbed?at=default

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM