问题
I would like to use GPGME for key generation and encryption in my C++ application. However, while trying to get started, I got stuck with a problem:
I dowloaded the dev package for my debian system. I told my compiler how to find the library. Just to see if I 'm able to initialize the library (mentioned here) I try to execute the following code..:
//--- Main.cpp---
#include <locale.h>
#include <gpgme.h>
int main(){
/* Initialize the locale environment. */
setlocale (LC_ALL, "");
gpgme_check_version (NULL);
gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
#ifdef LC_MESSAGES
gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
#endif
return 0;
}
the line
gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
is underlined in red by qt creator. The message is
expected token ';' got 'struct'
But why?
JFYI
As a synopsys of my earlier problem, my CMakeLists look like this:
My main CMakeLists.txt in the root directory of my project:
//...
include(FeatureSummary)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package(Gpgme)
# Additional include directories
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}
${GPGME_INCLUDES}
)
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/application/framework/impl)
And the CMakeLists.txt in application/framework/impl subdirectory:
# Define name of component
SET(COMPONENT_NAME framework)
# Define set of source files for library
SET(comp_src
//... well, the sources
)
add_executable(${COMPONENT_NAME} ${comp_src})
target_link_libraries(${COMPONENT_NAME} ${GPGME_VANILLA_LIBRARIES})
UPDATE
If I uncommend the line
//gpgme_check_version (NULL);
the message disappears. I checked the documentation. The signature of the method seams to be valid. Might there be something wrong with the library version I'm using?
EDIT:
This is not a compiler error, but just a red mark given by the qt creator. I would assume it should be caused by a typo or something. But I can't see any typo. Moreover the application does compile and run even if I didn't comment out the check_version
line.
来源:https://stackoverflow.com/questions/34614154/unexpected-struct-while-using-gpgme-in-c-application