I need to get away from cmake, so I want to build a qmake project on mingw. Please help me understand what is missing. Build CPPKafka from https://github.com/mfontanini/cppkafka
main.cpp
#include <cppkafka/cppkafka.h>
using namespace std;
using namespace cppkafka;
int main() {
Configuration config = { // Create the config
{ "metadata.broker.list", "127.0.0.1:9092" }
};
Producer producer(config); // Create the producer
string message = "hey there!"; // Produce a message!
producer.produce(MessageBuilder("my_topic").partition(0).payload(message));
producer.flush();
return 0;
}
.pro file
TEMPLATE = app
CONFIG += console c++14
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
INCLUDEPATH += 'C:\Program Files\CppKafka\include' \
'C:\Program Files\RdKafka\include' \
'C:\boost_1_72_0' \
'C:\Program Files\CppKafka\include\cppkafka'
LIBS += 'C:\Program Files\RdKafka\bin\librdkafka.dll' \
'C:\Program Files\RdKafka\bin\librdkafka++.dll' \
-lpthread \
-lz \
-lstdc++ \
'C:\Program Files\CppKafka\bin\libcppkafka.dll'
command
g++ -Wl,-subsystem,console -mthreads -o debug\cpp_kafka_ex.exe debug/main.o "C:\Program Files\RdKafka\bin\librdkafka.dll" "C:\Program Files\RdKafka\bin\librdkafka++.dll" -lpthread -lz -lstdc++ "C:\Program Files\CppKafka\bin\libcppkafka.dll"
link error
debug/main.o: In function std::unique_ptr<rd_kafka_s, cppkafka::KafkaHandleBase::HandleDeleter>::~unique_ptr()': C:/Qt/Tools/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/bits/unique_ptr.h:268: undefined reference to cppkafka::KafkaHandleBase::HandleDeleter::operator()(rd_kafka_s*)'
collect2.exe: error: ld returned 1 exit status
cmake
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
include_directories('C:\Program Files\RdKafka\include')
include_directories(C:\boost_1_72_0)
add_custom_target(examples)
macro(create_example example_name)
string(REPLACE "_" "-" sanitized_name ${example_name})
add_executable(${sanitized_name} EXCLUDE_FROM_ALL "${example_name}_example.cpp")
target_link_libraries(${sanitized_name} cppkafka RdKafka::rdkafka Boost::boost Boost::program_options)
add_dependencies(examples ${sanitized_name})
endmacro()
create_example(producer)
create_example(buffered_producer)
create_example(consumer)
create_example(consumer_dispatcher)
create_example(metadata)
create_example(consumers_information)
You need to add dllexport to the struct HandleDeleter and rebuild.
before include\cppkafka\kafka_handle_base.h:
struct HandleDeleter {
explicit HandleDeleter(const KafkaHandleBase* handle_base_ptr) : handle_base_ptr_{handle_base_ptr} {}
void operator()(rd_kafka_t* handle);
private:
const KafkaHandleBase * handle_base_ptr_;
};
after:
struct CPPKAFKA_API HandleDeleter {
explicit HandleDeleter(const KafkaHandleBase* handle_base_ptr) : handle_base_ptr_{handle_base_ptr} {}
void operator()(rd_kafka_t* handle);
private:
const KafkaHandleBase * handle_base_ptr_;
};
Related
It seems like to clang, binary operator && is exactly the same as and - its alternative operator representation. In the ast, both end up as BinaryOperator [...] 'bool' '&&'. Is there a way to distinguish them nevertheless?
I was hoping to be able to retrieve the actual source code string but have not been able to do so yet.
I am trying to do this using clang-tidy while writing a check that suggests using and instead of &&. I looked at clang::ASTContext, but didn't find anything that would get me anywhere.
As you have discovered, the AST itself does not distinguish between the
two ways to spell the operator. However, the AST has source location
information that can be used to get the original text. The idea is to
use:
clang::BinaryOperator::getOperatorLoc()
to get the start location of the operator, then
clang::Lexer::getLocForEndOfToken()
to get its end location, then
clang::Lexer::getSourceText()
to get the operator text.
Note that when the operator results from a macro expansion, the source
retrieval method I am using does not work well, and I do not know if
that can be fixed.
Here is the core of a clang-tidy check that does what you want (except
for cases involving macros):
// https://stackoverflow.com/questions/11083066/getting-the-source-behind-clangs-ast
std::string get_source_text_raw(SourceRange range, SourceManager const &sm)
{
return std::string(
clang::Lexer::getSourceText(
clang::CharSourceRange::getCharRange(range), sm, clang::LangOptions()
)
);
}
void FindOpAnd::registerMatchers(ast_matchers::MatchFinder *Finder)
{
// Match use of operator '&&' or 'and'.
Finder->addMatcher(
binaryOperator(hasOperatorName("&&"))
.bind("op"), this);
}
void FindOpAnd::check(const MatchFinder::MatchResult &Result)
{
ASTContext &context = *(Result.Context);
SourceManager &sm = context.getSourceManager();
// Get the node bound to "op" in the match expression.
const auto *opExpr = Result.Nodes.getNodeAs<BinaryOperator>("op");
// Location of the start of the operator.
SourceLocation opLoc = opExpr->getOperatorLoc();
// Try to find the location of the end.
SourceLocation opEndLoc =
clang::Lexer::getLocForEndOfToken(opLoc, 0, sm, clang::LangOptions());
if (opEndLoc.isValid()) {
// Get the text of the operator.
SourceRange opRange(opLoc, opEndLoc);
std::string opText = get_source_text_raw(opRange, sm);
if (opText == "&&") {
diag(opLoc, "Using '&&' instead of 'and'.")
<< FixItHint::CreateReplacement(opRange, "and");
}
else if (opText == "and") {
// This what we want.
}
else {
// This happens when the operator itself is the result of a macro
// expansion.
}
}
else {
// The end location will not be found if the operator was inside
// the expansion of a macro.
}
}
Sample input:
// op-and.cc
// Test input for clang-tidy FindOpAnd checker.
// Note: There are no digraphs or trigraphs for '&', so that is not a
// concern here.
#define MY_AMPER_OPERATOR &&
#define MY_AND_OPERATOR and
#define MY_AMPER_EXPR(a,b) ((a) && (b))
#define MY_AND_EXPR(a,b) ((a) and (b))
void f(bool a, bool b)
{
bool r;
r = a && b; // Reported.
r = a and b; // Not reported.
// Not reported: Operator name not recognized.
r = a MY_AMPER_OPERATOR b;
r = a MY_AND_OPERATOR b;
// Not reported: Operator end location is invalid so we cannot get the
// operator name.
r = MY_AMPER_EXPR(a,b);
r = MY_AND_EXPR(a,b);
}
// EOF
Sample output:
$ ./FindOpAnd.exe -checks=-*,FindOpAnd in/op-and.cc \
--export-fixes=out/op-and.cc.fixes.yaml --
1 warning generated.
[...]/in/op-and.cc:17:9: warning: Using '&&' instead of 'and'. [FindOpAnd]
r = a && b; // Reported.
^~
and
To actually apply the suggested fixes, pass the --fix option.
For completeness, here is the full checker source and its Makefile:
// FindOpAnd.cc
// Code for FindOpAnd.h.
#include "FindOpAnd.h" // this module
#include "clang/AST/ASTContext.h" // ASTContext
#include "clang/Lex/Lexer.h" // clang::Lexer
#include "clang-tidy/ClangTidyModule.h" // ClangTidyModule
#include "clang-tidy/ClangTidyModuleRegistry.h" // ClangTidyModuleRegistry
using namespace clang::ast_matchers;
namespace clang {
namespace tidy {
// https://stackoverflow.com/questions/11083066/getting-the-source-behind-clangs-ast
std::string get_source_text_raw(SourceRange range, SourceManager const &sm)
{
return std::string(
clang::Lexer::getSourceText(
clang::CharSourceRange::getCharRange(range), sm, clang::LangOptions()
)
);
}
void FindOpAnd::registerMatchers(ast_matchers::MatchFinder *Finder)
{
// Match use of operator '&&' or 'and'.
Finder->addMatcher(
binaryOperator(hasOperatorName("&&"))
.bind("op"), this);
}
void FindOpAnd::check(const MatchFinder::MatchResult &Result)
{
ASTContext &context = *(Result.Context);
SourceManager &sm = context.getSourceManager();
// Get the node bound to "op" in the match expression.
const auto *opExpr = Result.Nodes.getNodeAs<BinaryOperator>("op");
// Location of the start of the operator.
SourceLocation opLoc = opExpr->getOperatorLoc();
// Try to find the location of the end.
SourceLocation opEndLoc =
clang::Lexer::getLocForEndOfToken(opLoc, 0, sm, clang::LangOptions());
if (opEndLoc.isValid()) {
// Get the text of the operator.
SourceRange opRange(opLoc, opEndLoc);
std::string opText = get_source_text_raw(opRange, sm);
if (opText == "&&") {
diag(opLoc, "Using '&&' instead of 'and'.")
<< FixItHint::CreateReplacement(opRange, "and");
}
else if (opText == "and") {
// This what we want.
}
else {
// This happens when the operator itself is the result of a macro
// expansion.
}
}
else {
// The end location will not be found if the operator was inside
// the expansion of a macro.
}
}
class FindOpAndModule : public ClangTidyModule {
public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
CheckFactories.registerCheck<FindOpAnd>("FindOpAnd");
}
};
static ClangTidyModuleRegistry::Add<FindOpAndModule> X(
"FindOpAndModule",
"Adds FindOpAnd check.");
// This is defined in libclangTidyMain.a. It does not appear to be
// declared in any header file, so I doubt this is really how it is
// meant to be used.
int clangTidyMain(int argc, const char **argv);
} // namespace tidy
} // namespace clang
int main(int argc, const char **argv)
{
return clang::tidy::clangTidyMain(argc, argv);
}
// EOF
// FindOpAnd.h
// clang-tidy check to find operator '&&' as opposed to 'and'.
#ifndef FIND_OP_AND_H
#define FIND_OP_AND_H
#include "clang-tidy/ClangTidyCheck.h" // ClangTidyCheck
#include "clang/ASTMatchers/ASTMatchFinder.h" // ast_matchers::MatchFinder
namespace clang {
namespace tidy {
class FindOpAnd : public ClangTidyCheck {
public:
FindOpAnd(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
} // namespace tidy
} // namespace clang
#endif // FIND_OP_AND_H
# clang-tidy-op-and/Makefile
# Default target.
all:
.PHONY: all
# Eliminate all implicit rules.
.SUFFIXES:
# Delete a target when its recipe fails.
.DELETE_ON_ERROR:
# Do not remove "intermediate" targets.
.SECONDARY:
# ---- Paths ----
# Installation directory from a binary distribution.
# Has five subdirectories: bin include lib libexec share.
# Downloaded from: https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz
CLANG_LLVM_INSTALL_DIR = $(HOME)/opt/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04
# Program to query the various LLVM configuration options.
LLVM_CONFIG = $(CLANG_LLVM_INSTALL_DIR)/bin/llvm-config
# ---- Compiler options ----
# C++ compiler.
CXX = g++
# Compiler options, including preprocessor options.
CXXFLAGS =
CXXFLAGS += -Wall
# Get llvm compilation flags.
CXXFLAGS += $(shell $(LLVM_CONFIG) --cxxflags)
# Linker options.
LDFLAGS =
# Needed libraries. The order is important. I do not know a principled
# way to obtain this list. I did it by chasing down each missing symbol
# in a link error.
LDFLAGS += -lclangTidy
LDFLAGS += -lclangTidyMain
LDFLAGS += -lclangTidyPlugin
LDFLAGS += -lclangToolingCore
LDFLAGS += -lclangFormat
LDFLAGS += -lclangToolingInclusions
LDFLAGS += -lclangTidyAbseilModule
LDFLAGS += -lclangTidyAlteraModule
LDFLAGS += -lclangTidyAndroidModule
LDFLAGS += -lclangTidyBoostModule
LDFLAGS += -lclangTidyBugproneModule
LDFLAGS += -lclangTidyCERTModule
LDFLAGS += -lclangTidyConcurrencyModule
LDFLAGS += -lclangTidyCppCoreGuidelinesModule
LDFLAGS += -lclangTidyDarwinModule
LDFLAGS += -lclangTidyFuchsiaModule
LDFLAGS += -lclangTidyGoogleModule
LDFLAGS += -lclangTidyHICPPModule
LDFLAGS += -lclangTidyLLVMLibcModule
LDFLAGS += -lclangTidyLLVMModule
LDFLAGS += -lclangTidyLinuxKernelModule
LDFLAGS += -lclangTidyMPIModule
LDFLAGS += -lclangTidyMiscModule
LDFLAGS += -lclangTidyModernizeModule
LDFLAGS += -lclangTidyObjCModule
LDFLAGS += -lclangTidyOpenMPModule
LDFLAGS += -lclangTidyPerformanceModule
LDFLAGS += -lclangTidyPortabilityModule
LDFLAGS += -lclangTidyReadabilityModule
LDFLAGS += -lclangTidyZirconModule
LDFLAGS += -lclangTidyUtils
LDFLAGS += -lclangTransformer
LDFLAGS += -lclangTooling
LDFLAGS += -lclangFrontendTool
LDFLAGS += -lclangFrontend
LDFLAGS += -lclangDriver
LDFLAGS += -lclangSerialization
LDFLAGS += -lclangCodeGen
LDFLAGS += -lclangParse
LDFLAGS += -lclangSema
LDFLAGS += -lclangStaticAnalyzerFrontend
LDFLAGS += -lclangStaticAnalyzerCheckers
LDFLAGS += -lclangStaticAnalyzerCore
LDFLAGS += -lclangAnalysis
LDFLAGS += -lclangARCMigrate
LDFLAGS += -lclangRewrite
LDFLAGS += -lclangRewriteFrontend
LDFLAGS += -lclangEdit
LDFLAGS += -lclangCrossTU
LDFLAGS += -lclangIndex
LDFLAGS += -lclangAST
LDFLAGS += -lclangASTMatchers
LDFLAGS += -lclangLex
LDFLAGS += -lclangBasic
LDFLAGS += -lclang
# *After* clang libs, the llvm libs.
LDFLAGS += $(shell $(LLVM_CONFIG) --ldflags --libs --system-libs)
# ---- Recipes ----
# Pull in automatic dependencies.
-include $(wildcard obj/*.d)
# Compile a C++ source file.
obj/%.o: %.cc
#mkdir -p $(dir $#)
$(CXX) -MMD -c -o $# $(USE_PCH) $< $(CXXFLAGS)
# Sources for 'FindOpAnd.exe'.
SRCS :=
SRCS += FindOpAnd.cc
# Objects for 'FindOpAnd.exe'.
OBJS := $(patsubst %.cc,obj/%.o,$(SRCS))
# Executable.
all: FindOpAnd.exe
FindOpAnd.exe: $(OBJS)
$(CXX) -g -Wall -o $# $(OBJS) $(LDFLAGS)
# Run program on one input.
out/%: in/% FindOpAnd.exe
#mkdir -p $(dir $#)
./FindOpAnd.exe -checks=-*,FindOpAnd in/$* \
--export-fixes=out/$*.fixes.yaml \
-- </dev/null 2>&1 | cat
touch $#
# Run tests.
.PHONY: check
check: FindOpAnd.exe
check: out/op-and.cc
# Remove test outputs.
.PHONY: check-clean
check-clean:
rm -rf out
# Remove compile and test outputs.
.PHONY: clean
clean: check-clean
$(RM) *.exe
rm -rf obj
# EOF
I've build CGAL like explained here.
Everything went well.
But now, I'm using Qt Creator with CGAL.
I've included the libraries in the .pro file :
QT += core
QT -= gui
TARGET = TestCCGALAppliConsole
CONFIG += console
CONFIG -= app_bundle
CONFIG += c++11
TEMPLATE = app
INCLUDEPATH += /usr/local/include
DEPENDPATH += /usr/local/include
LIBS += -L/usr/local/include
macx: LIBS += -L/usr/local/lib/ -lgmp
macx: LIBS += -L/usr/local/lib/ -lmpfr
macx: LIBS += -L/usr/local/lib/ -lCGAL
SOURCES += main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../local/CGAL-4.6/build/lib/release/ -lCGAL-vc100-mt-gd-4.6
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../local/CGAL-4.6/build/lib/debug/ -lCGAL-vc100-mt-4.6
INCLUDEPATH += $$PWD/../../../../local/CGAL-4.6/build/lib/Debug
DEPENDPATH += $$PWD/../../../../local/CGAL-4.6/build/lib/Debug
INCLUDEPATH += C:\local\CGAL-4.6\include
win32: LIBS += -L$$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/lib/ -llibgmp-10
INCLUDEPATH += $$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/include
DEPENDPATH += $$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/include
win32: LIBS += -L$$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/lib/ -llibmpfr-4
INCLUDEPATH += $$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/include
DEPENDPATH += $$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/include
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0/ -lboost_system-vc100-mt-1_57
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0/ -lboost_system-vc100-mt-gd-1_57
INCLUDEPATH += $$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0
DEPENDPATH += $$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0/ -lboost_thread-vc100-mt-1_57
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0/ -lboost_thread-vc100-mt-gd-1_57
INCLUDEPATH += $$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0
DEPENDPATH += $$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0
INCLUDEPATH += C:\local\boost_1_57_0
and in my main.cpp I have :
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Polyhedron_items_with_id_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <iostream>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Polyhedron_3<K, CGAL::Polyhedron_items_with_id_3> Polyhedron;
typedef Polyhedron::Vertex_iterator Vertex_iterator;
int main() {
Polyhedron mesh;
std::ifstream input("inner.off");
if ( !input || !(input >> mesh) || mesh.empty() )
{
//Debug
std::cerr << "Not a valid off file." << std::endl;
return 0;
}
for (Vertex_iterator v = mesh.vertices_begin() ; v!= mesh.vertices_end() ; ++v )
{
std::cout << v->point() << std::endl;
}
std::cout << "Hello You" << std::endl;
return 0;
}
when I compile (with MinGW 4.9.1 32 bit with Qt 5.4.1) I'm having this error :
C:\local\CGAL-4.6\include\CGAL\double.h:191: erreur : '_nextafter' was
not declared in this scope return _nextafter(d1, d2); // works at
least for VC++-7.1
I can't figure out what's wrong...
Can you help me ?
EDIT
It seems that CGAL being compiled with Visual Studio C++ Compiler 10 involves that I have to compile with this compiler and not MinGW.
So I changed compile, I'm now using Microsoft Visual C++ Compiler 10 (amd64) in Qt Creator, but it still don't work. I have an error :
impossible to open 'CGAL-vc100-mt-4.6.lib' file
Here's the complete error (sorry, french version...) :
17:42:15: Exécution des étapes pour le projet TestCCGALAppliConsole...
17:42:15: Configuration inchangée, étape qmake sautée.
17:42:15: Débute : "C:\Qt\Tools\QtCreator\bin\jom.exe"
C:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile.Debug
cl -c -nologo -Zm200 -Zc:wchar_t -Zi -MDd -GR -W3 -w34100 -w34189 -EHsc /Fddebug\TestCCGALAppliConsole.pdb -DUNICODE -DWIN32 -DWIN64 -DQT_CORE_LIB -I"..\TestCCGALAppliConsole" -I"." -I"\usr\local\include" -I"..\..\..\..\local\CGAL-4.6\build\lib\Debug" -I"..\..\..\..\local\CGAL-4.6\include" -I"..\..\..\..\local\CGAL-4.6\auxiliary\gmp\include" -I"..\..\..\..\local\CGAL-4.6\auxiliary\gmp\include" -I"..\..\..\..\local\boost_1_57_0\lib64-msvc-10.0" -I"..\..\..\..\local\boost_1_57_0\lib64-msvc-10.0" -I"..\..\..\..\local\boost_1_57_0" -I"..\..\..\..\Qt\qt-5.4.1-x64-msvc2010-rev1\qt-5.4.1-x64-msvc2010-rev1\include" -I"..\..\..\..\Qt\qt-5.4.1-x64-msvc2010-rev1\qt-5.4.1-x64-msvc2010-rev1\include\QtCore" -I"debug" -I"..\..\..\..\Qt\qt-5.4.1-x64-msvc2010-rev1\qt-5.4.1-x64-msvc2010-rev1\mkspecs\win32-msvc2010" -Fodebug\ #C:\Users\Raphael\AppData\Local\Temp\main.obj.1988.32.jom
main.cpp
echo 1 /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ 24 /* RT_MANIFEST */ "debug\\TestCCGALAppliConsole.exe.embed.manifest">debug\TestCCGALAppliConsole.exe_manifest.rc
if not exist debug\TestCCGALAppliConsole.exe if exist debug\TestCCGALAppliConsole.exe.embed.manifest del debug\TestCCGALAppliConsole.exe.embed.manifest
if exist debug\TestCCGALAppliConsole.exe.embed.manifest copy /Y debug\TestCCGALAppliConsole.exe.embed.manifest debug\TestCCGALAppliConsole.exe_manifest.bak
link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST /MANIFESTFILE:debug\TestCCGALAppliConsole.exe.embed.manifest /OUT:debug\TestCCGALAppliConsole.exe #C:\Users\Raphael\AppData\Local\Temp\TestCCGALAppliConsole.exe.1988.5000.jom
LINK : fatal error LNK1104: impossible d'ouvrir le fichier 'CGAL-vc100-mt-4.6.lib'
jom: C:\Users\Raphael\Desktop\build-TestCCGALAppliConsole-Desktop_Qt_5_4_1_MSVC2010_x64-Debug\Makefile.Debug [debug\TestCCGALAppliConsole.exe] Error 1104
jom: C:\Users\Raphael\Desktop\build-TestCCGALAppliConsole-Desktop_Qt_5_4_1_MSVC2010_x64-Debug\Makefile [debug] Error 2
17:42:21: Le processus "C:\Qt\Tools\QtCreator\bin\jom.exe" s'est terminé avec le code 2.
Erreur lors de la compilation/déploiement du projet TestCCGALAppliConsole (kit : Desktop Qt 5.4.1 MSVC2010 x64)
When executing step "Make"
17:42:21: Temps écoulé : 00:05.
Well, it's right there in your message:
when I compile (with MinGW
versus
works at least for VC++-7.1
_nextafter is a Microsoft extension used by CGAL. MinGW doesn't appear to support it.
I am trying to get a project working with SDL2, assimp, opengl, and glew and cannot get glew to link properly (almost a duplicate but a more comprehensive question and answer, I think).
My qmake .pro file :
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
HEADERS += \
objloader.h \
display.h \
eventloop.h \
shader.h \
texture.h
SOURCES += main.cpp \
objloader.cpp \
display.cpp \
eventloop.cpp \
shader.cpp \
texture.cpp
INCLUDEPATH += "C:/code middleware/glew-1.12.0/include/" \
"C:\code middleware\glm\\" \
"C:\code middleware\SDL2-2.0.3\include\\" \
"C:\Users\smart_000\Desktop\assimp\include\\"
DEPENDPATH += "C:/code middleware/glew-1.10.0/bin/Release\Win32/" \
"C:\code middleware\SDL2-2.0.3\lib/x86/" \
"C:/Users/smart_000/Desktop/assimp/bin/" \
"C:/code middleware/glew-1.12.0/lib/Release/Win32/" \
"C:/code middleware/glew-1.12.0/bin/Release/Win32/"
LIBS += -L"C:\code middleware\SDL2-2.0.3\lib\x86" -lSDL2main -lSDL2
LIBS += -L"C:/Users/smart_000/Desktop/assimp/lib/" -lassimp.dll -lzlib
LIBS += -lopengl32
LIBS += -lglu32
LIBS += -L"C:/code middleware/glew-1.12.0/lib/Release/Win32/" -lglew32 -lglu32
The linker errors I am getting: linker errors
What I have tried already:
Checking file path problems ('/' and '\' kind of stuff and spaces in file names etc.)
Linking dynamically and statically (Yes, I defined GLEW_STATIC where I needed to, and I linked to -lglew32s and such)
SDL stuff: messing with and defining 'NO_SDL_GLEXT' above it
Making test programs and trying to link it with just g++ (I used the -static flag where I should have when I tried the static one and placed the linker flags after the files that needed them). These errors were the same as the qt ones minus the warnings.
Putting the glew source code directly in my project and building it (exact same errors) --- The issues were eerily similar and made no sense to me. I had commented out the qmake stuff and re ran qmake; I wasn't aware I could get linker errors like that if I put it in my project like I did.
Running qmake after my changes, lol
Moving 'LIBS' and 'DEPENDPATH' around and added 'CONFIG += opengl' in desperation
Messing with debug and release builds.
What I haven't tried:
Moving libraries and things to the system path
MAKING SURE THE LIBRARIES WERE BUILT FOR MINGW!
The relevant code(I know it's terrible; I was just hacking around when I encountered these issues) :
"main.cpp" :
#include <GL/glew.h>
#include <iostream>
#include <SDL.h>
#include <objloader.h>
#include "display.h"
#include "eventloop.h"
Display* display = NULL;
void callback()
{
std::cout << "yay" << std::endl;
display->Swap();
}
int main(int argc, char* argv[])
{
UShortVector indices;
Vec3Vector vertices;
Vec2Vector uvs;
Vec3Vector normals;
bool success = ObjLoader::loadObj("cube.obj", indices, vertices, uvs, normals);
display = new Display();
EventLoop eventLoop;
eventLoop.SetLoopCallback(&callback);
display->Create("yay");
eventLoop.Start();
return 0;
}
"display.h"
#ifndef DISPLAY_H
#define DISPLAY_H
#include <GL/glew.h>
#include <SDL.h>
#include <iostream>
class Display
{
public:
Display();
~Display();
void Create(const char* title);
void Swap();
SDL_Window* window_ = NULL;
SDL_GLContext glContext_;
};
#endif // DISPLAY_H
"shader.h"
#ifndef SHADER_H
#define SHADER_H
#include <GL/glew.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <memory.h>
class Shader
{
public:
GLuint LoadShaders(const char * vertex_file_path, const char * fragment_file_path);
private:
Shader();
~Shader();
};
#endif // SHADER_H
"shader.cpp"
#include "shader.h"
Shader::Shader()
{
}
Shader::~Shader()
{
}
GLuint Shader::LoadShaders(const char * vertexShaderPath, const char * fragmentShaderPath)
{
FILE* vertexFile = fopen(vertexShaderPath, "r");
FILE* fragmentFile = fopen(fragmentShaderPath, "r");
if(!vertexFile || !fragmentFile)
{
if(!vertexFile)
{
perror("could not open the vertex shader file");
}
if(!fragmentFile)
{
perror("could not open the fragment shader file");
}
}
GLuint programID = glCreateProgram();
GLuint vertShader = glCreateShader(GL_VERTEX_SHADER);
GLuint fragShader = glCreateShader(GL_FRAGMENT_SHADER);
const size_t MAX_LINE_LENGTH = 120;
char line[MAX_LINE_LENGTH];
std::vector<GLchar*> vertShaderSource;
std::vector<GLchar*> fragmentShaderSource;
while(fgets(line, MAX_LINE_LENGTH, vertexFile) != NULL)
{
vertShaderSource.push_back((GLchar*)line);
memset((void*)line, '\0', sizeof(line));
}
while(fgets(line, MAX_LINE_LENGTH, fragmentFile) != NULL)
{
fragmentShaderSource.push_back((GLchar*)line);
memset((void*)line, '\0', sizeof(line));
}
glShaderSource(vertShader, vertShaderSource.size(), (const GLchar**)&vertShaderSource, NULL);
glShaderSource(fragShader, fragmentShaderSource.size(), (const GLchar**)&fragmentShaderSource, NULL);
// doesn't do anything at the moment, I know. It should still compile though.
return programID;
}
Right after I posted the question, I found the issue. Embarrassingly, it was an issue I have run into before with assimp (although I just now realized why re-building it with cmake worked).
The hallmarks:
Weird linker errors with a library when you know the library is being found.
You primarily work on a windows system :)
The solution:
Check the build kit that you are using with Qt creator Vs. the libs you are using.
I was using the MINGW one only and my libs were compiled using the MSVC++ compiler
The libs you are looking for are .a files: specifically lib{name}.a . In this case, I was looking for libglew32.dll.a <- note the .dll in there for whether it is a dll import library or a static one like libglew32s.a <- note the s for static.
Where to go to get the rights libs :
- Go here for building it: Building glew on windows with mingw.
- Go here to download the pre-built one that I did (older version of glew): https://launchpad.net/glew-cmake/+milestone/1.10.0
The Download link that I used: glew-gcc-1.10.0-win32.zip (md5) Glew-Cmake 1.10.0 Binaries (MinGW) <- I tried to post a picture, but apparently, I am not cool enough to do that yet.
My updated and working qmake .pro file :
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
HEADERS += \
objloader.h \
display.h \
eventloop.h \
shader.h \
texture.h
SOURCES += main.cpp \
objloader.cpp \
display.cpp \
eventloop.cpp \
shader.cpp \
texture.cpp
INCLUDEPATH += "C:/code middleware/glew-gcc-1.10.0-win32/include/" \
"C:/code middleware/glm/" \
"C:/code middleware/SDL2-2.0.3/include/" \
"C:/Users/smart_000/Desktop/assimp/include/"
DEPENDPATH += "C:/code middleware/SDL2-2.0.3/lib/x86/" \
"C:/Users/smart_000/Desktop/assimp/bin/" \
"C:/code middleware/glew-gcc-1.10.0-win32/lib/" \
"C:/code middleware/glew-gcc-1.10.0-win32/bin/"
LIBS += -L"C:/code middleware/SDL2-2.0.3/lib/x86" -lSDL2main -lSDL2
LIBS += -L"C:/Users/smart_000/Desktop/assimp/lib/" -lassimp.dll -lzlib
LIBS += -L"C:/code middleware/glew-gcc-1.10.0-win32/lib/" -lglew32.dll
LIBS += -lopengl32
LIBS += -lglu32
Note: Don't forget the .dll on the end of the libs (-lglew32.dll).
- Happy Linking!
I have installed PocketSphinx on Ubuntu 14 and now trying to create simple sample. I took code from official website Sphinx.
#include <pocketsphinx.h>
int
main(int argc, char *argv[])
{
ps_decoder_t *ps;
cmd_ln_t *config;
FILE *fh;
char const *hyp, *uttid;
int16 buf[512];
int rv;
int32 score;
config = cmd_ln_init(NULL, ps_args(), TRUE,
"-hmm", MODELDIR "/en-us/en-us",
"-lm", MODELDIR "/en-us/en-us.lm.dmp",
"-dict", MODELDIR "/en-us/cmudict-en-us.dict",
NULL);
if (config == NULL)
return 1;
ps = ps_init(config);
if (ps == NULL)
return 1;
fh = fopen("goforward.raw", "rb");
if (fh == NULL)
return -1;
rv = ps_start_utt(ps);
if (rv < 0)
return 1;
while (!feof(fh)) {
size_t nsamp;
nsamp = fread(buf, 2, 512, fh);
rv = ps_process_raw(ps, buf, nsamp, FALSE, FALSE);
}
rv = ps_end_utt(ps);
if (rv < 0)
return 1;
hyp = ps_get_hyp(ps, &score);
if (hyp == NULL)
return 1;
printf("Recognized: %s\n", hyp);
fclose(fh);
ps_free(ps);
cmd_ln_free_r(config);
return 0;
}
And Qmake is
QT += core
QT -= gui
TARGET = OpenCVQt
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
DEPENDPATH += /usr/local/lib
INCLUDEPATH += /usr/local/include
INCLUDEPATH += /usr/local/include/pocketsphinx
INCLUDEPATH += /usr/local/include/sphinxbase
LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_highgui
LIBS +=-lpocketsphinx
LIBS += -lsphinxbase
LIBS += -lsphinxad
SOURCES += main.cpp
Can't understand what is wrong. I saw sphinx_config.h in /usr/local/include/sphinxbase. Thanks.
18:54:06: Starting: "/usr/bin/make"
/home/warezovvv/Qt/5.4/gcc_64/bin/qmake -spec linux-g++ CONFIG+=debug -o Makefile ../OpenCVQt/OpenCVQt.pro
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_CORE_LIB -I../OpenCVQt -I. -I/usr/local/include -I/usr/local/include/pocketsphinx -I/usr/local/include/sphinxbase -I../../../Qt/5.4/gcc_64/include -I../../../Qt/5.4/gcc_64/include/QtCore -I. -I../../../Qt/5.4/gcc_64/mkspecs/linux-g++ -o main.o ../OpenCVQt/main.cpp
In file included from /usr/include/sphinxbase/cmd_ln.h:66:0,
from /usr/local/include/pocketsphinx/pocketsphinx.h:52,
from ../OpenCVQt/main.cpp:1:
/usr/include/sphinxbase/prim_type.h:88:27: fatal error: sphinx_config.h: No such file or directory
#include <sphinx_config.h>
^
compilation terminated.
make: *** [main.o] Error 1
18:54:06: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project OpenCVQt (kit: Desktop Qt 5.4.1 GCC 64bit)
When executing step "Make"
18:54:06: Elapsed time: 00:01.
No error with header. Now new error ->
22:42:41: Running steps for project OpenCVQt...
22:42:41: Configuration unchanged, skipping qmake step.
22:42:41: Starting: "/usr/bin/make"
/home/warezovvv/Qt/5.4/gcc_64/bin/qmake -spec linux-g++ CONFIG+=debug -o Makefile ../OpenCVQt/OpenCVQt.pro
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_CORE_LIB -I../OpenCVQt -I. -I/usr/local/include -I/usr/local/include/pocketsphinx -I/usr/local/include/sphinxbase -I/usr/include/sphinxbase -I../../../Qt/5.4/gcc_64/include -I../../../Qt/5.4/gcc_64/include/QtCore -I. -I../../../Qt/5.4/gcc_64/mkspecs/linux-g++ -o main.o ../OpenCVQt/main.cpp
../OpenCVQt/main.cpp: In function 'int main(int, char**)':
../OpenCVQt/main.cpp:14:22: error: 'MODELDIR' was not declared in this scope
"-hmm", MODELDIR "/en-us/en-us",
^
../OpenCVQt/main.cpp:15:30: error: expected ')' before string constant
"-lm", MODELDIR "/en-us/en-us.lm.dmp",
^
../OpenCVQt/main.cpp:16:32: error: expected ')' before string constant
"-dict", MODELDIR "/en-us/cmudict-en-us.dict",
^
../OpenCVQt/main.cpp:9:23: warning: unused variable 'uttid' [-Wunused-variable]
char const *hyp, *uttid;
^
../OpenCVQt/main.cpp: At global scope:
../OpenCVQt/main.cpp:4:1: warning: unused parameter 'argc' [-Wunused-parameter]
main(int argc, char *argv[])
^
../OpenCVQt/main.cpp:4:1: warning: unused parameter 'argv' [-Wunused-parameter]
make: *** [main.o] Error 1
22:42:42: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project OpenCVQt (kit: Desktop Qt 5.4.1 GCC 64bit)
When executing step "Make"
22:42:42: Elapsed time: 00:01.
I solved it with this CMake config:
cmake_minimum_required(VERSION 2.8)
add_definitions(-std=c++11)
find_package(PkgConfig REQUIRED)
pkg_check_modules(POCKETSPHINX REQUIRED pocketsphinx)
pkg_check_modules(SPHINXBASE REQUIRED sphinxbase)
message(STATUS "SPHINXBASE_LIBRARIES => " "${SPHINXBASE_LIBRARIES}")
message(STATUS "POCKETSPHINX_LIBRARIES => " "${POCKETSPHINX_LIBRARIES}")
message(STATUS "POCKETSPHINX_INCLUDE_DIRS => " "${POCKETSPHINX_INCLUDE_DIRS}")
message(STATUS "SPHINXBASE_INCLUDE_DIRS => " "${SPHINXBASE_INCLUDE_DIRS}")
set(
your_pocketsphinx_app_src
your_pocketsphinx_app.cpp
...
)
add_executable(your_pocketsphinx_app your_pocketsphinx_app.cpp)
set_property(TARGET your_pocketsphinx_app PROPERTY CXX_STANDARD 11)
target_include_directories(your_pocketsphinx_app PUBLIC ${POCKETSPHINX_INCLUDE_DIRS})
target_include_directories(your_pocketsphinx_app PUBLIC ${SPHINXBASE_INCLUDE_DIRS})
target_compile_options(your_pocketsphinx_app PUBLIC ${POCKETSPHINX_CFLAGS_OTHER})
target_compile_options(your_pocketsphinx_app PUBLIC ${SPHINXBASE_CFLAGS_OTHER})
target_link_libraries(your_pocketsphinx_app ${SPHINXBASE_LIBRARIES})
target_link_libraries(your_pocketsphinx_app ${POCKETSPHINX_LIBRARIES})
# Binary to be installed.
install(TARGETS your_pocketsphinx_app DESTINATION bin)
You seem to have installation of sphinxbase headers in /usr/include, not in /usr/local/include. If you intentionally compiled sphinxbase this way, you need to add -I/usr/include/sphinxbase in Makefile, not -I/usr/local/include/sphinxbase.
Overall pocketsphinx-5prealpha requires sphinxbase-5prealpha and default installation prefix for them is /usr/local. I suggest you to remove sphinxbase from /usr.
I am running QtCreator on Mac... I want to start working on boost libraries ... So, I installed boost libraries using
brew install boost
After that I created a small boost hallo world program and made the changes in .pro file as follows
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
unix:INCLUDEPATH += "/usr/local/Cellar/boost/1.55.0_1/include/"
unix:LIBPATH += "-L/usr/local/Cellar/boost/1.55.0_1/lib/"
SOURCES += main.cpp
LIBS += \
-lboost_date_time \
-lboost_filesystem \
-lboost_program_options \
-lboost_regex \
-lboost_signals \
-lboost_system
I am still unable to build... What could be the reason? Please suggest me what could be the possible mistake...
The errors are
library not found for -lboost_data_time
linker command failed with exit code 1 (use -v to see invocation)
This is taking a bit from Uflex's answer, as he missed something.
So keep the same code:
//make sure that there is a boost folder in your boost include directory
#include <boost/chrono.hpp>
#include <cmath>
int main()
{
auto start = boost::chrono::system_clock::now();
for ( long i = 0; i < 10000000; ++i )
std::sqrt( 123.456L ); // burn some time
auto sec = boost::chrono::system_clock::now() - start;
std::cout << "took " << sec.count() << " seconds" << std::endl;
return 0;
}
But lets change his .pro a bit:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
macx {
QMAKE_CXXFLAGS += -std=c++11
_BOOST_PATH = /usr/local/Cellar/boost/1.55.0_1
INCLUDEPATH += "$${_BOOST_PATH}/include/"
LIBS += -L$${_BOOST_PATH}/lib
## Use only one of these:
LIBS += -lboost_chrono-mt -lboost_system # using dynamic lib (not sure if you need that "-mt" at the end or not)
#LIBS += $${_BOOST_PATH}/lib/libboost_chrono-mt.a # using static lib
}
The only thing I have added to this was the boost system( -lboost_system )
That should solve the issue with his original version causing the undefined symbols, and allow you to add your other libraries.
Such as -lboost_date_time, which for me worked perfectly with the brew install.
Granted, my path is actually: /usr/local/Cellar/boost/1.55.0_2
Boost libraries are modularized, you just need to link against the libraries that you are using. Some libraries are header only, so you don't need to do anything, having boost reachable in your path is enough.
You can try to compile this:
//make sure that there is a boost folder in your boost include directory
#include <boost/chrono.hpp>
#include <cmath>
int main()
{
auto start = boost::chrono::system_clock::now();
for ( long i = 0; i < 10000000; ++i )
std::sqrt( 123.456L ); // burn some time
auto sec = boost::chrono::system_clock::now() - start;
std::cout << "took " << sec.count() << " seconds" << std::endl;
return 0;
}
And in the .pro file:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
macx {
QMAKE_CXXFLAGS += -std=c++11
_BOOST_PATH = /usr/local/Cellar/boost/1.55.0_1
INCLUDEPATH += "$${_BOOST_PATH}/include/"
LIBS += -L$${_BOOST_PATH}/lib
## Use only one of these:
LIBS += -lboost_chrono-mt # using dynamic lib (not sure if you need that "-mt" at the end or not)
#LIBS += $${_BOOST_PATH}/lib/libboost_chrono-mt.a # using static lib
}