g++

How to suppress OpenCV error message

徘徊边缘 提交于 2019-12-17 20:17:59
问题 I am writing an OpenCV project using g++ and opencv 2.4.6 I have some code like this: try { H = findHomography( obj, scene, CV_RANSAC ); } catch (Exception &e) { if (showOutput) cout<< "Error throwed when finding homography"<<endl; errorCount++; if (errorCount >=10) { errorCount = 0; selected_temp = -99; foundBB = false; bb_x1 = 0; bb_x2 = 0; bb_y1 = 0; bb_y2 = 0; } return -1; } Error will be thrown when the findHomography failed to find things. The error message includes: OpenCV Error:

g++ 4.9 rejects valid aggregate initialization in C++14

余生长醉 提交于 2019-12-17 19:53:22
问题 Consider this code: struct S { int x; double y = 1.1; }; int main() { S s = {0}; } According to the C++14 standard, § 8.5.1/7 If there are fewer initializer-clauses in the list than there are members in the aggregate, then each member not explicitly initialized shall be initialized from its brace-or-equal-initializer or, if there is no brace-or-equal- initializer, from an empty initializer list (8.5.4). the code should be perfectly valid. However, g++ 4.9.2 rejects the code (compiled with

Using JNI to execute a java jar from a C++ program, using g++ or eclipse

99封情书 提交于 2019-12-17 19:31:40
问题 I'm trying to call / execute a java jar from a C++ program. Here are the options I've found so far: Use JNI Use Jace Use JunC++ion Use execl("java", "java", "-jar", "myprog.jar", NULL); Use execlp("java", "java", "-jar", "myprog.jar", (char *)0); Use system("java filename.jar"); Use popen("java -jar test.jar text1 text2", "r"); Use CreateProcess(...); Use JNA I'd like to use JNI, however I'm running into problems. ======================== Hello.cpp I have a simple Hello.cpp class: #include

Linker error when compiling boost.asio example

天涯浪子 提交于 2019-12-17 18:54:41
问题 I'm trying to learn a little bit C++ and Boost.Asio. I'm trying to compile the following code example: #include <iostream> #include <boost/array.hpp> #include <boost/asio.hpp> using boost::asio::ip::tcp; int main(int argc, char* argv[]) { try { if (argc != 2) { std::cerr << "Usage: client <host>" << std::endl; return 1; } boost::asio::io_service io_service; tcp::resolver resolver(io_service); tcp::resolver::query query(argv[1], "daytime"); tcp::resolver::iterator endpoint_iterator = resolver

g++ treats returned string literal as const char pointer not const char array

核能气质少年 提交于 2019-12-17 18:54:21
问题 I'm seeing some odd behaviour when returning a string literal from a function that should perform an implicit conversion with g++ (version 4.7.3). Can anyone explain why the following code: #include <stdio.h> class Test { public: template <unsigned int N> Test(const char (&foo)[N]) { printf("Template const char array constructor\n"); } Test(char* foo) { printf("char* constructor\n"); } }; Test fn() { return "foo"; } int main() { Test t("bar"); Test u = fn(); return 0; } produces the result:

Which C++ standard is the default when compiling with g++?

送分小仙女□ 提交于 2019-12-17 18:25:28
问题 I have a piece of code that looks like the following. Let's say it's in a file named example.cpp #include <fstream> #include <string> // line added after edit for clarity int main() { std::string filename = "input.txt"; std::ifstream in(filename); return 0; } On a windows, if I type in the cmd the command g++ example.cpp , it will fail. It's a long list of errors I think mostly due to the linker complaining about not being able to convert from string to const char* . But if I run the compiler

How do I compile for 64bit using G++ w/ CodeBlocks?

↘锁芯ラ 提交于 2019-12-17 18:24:36
问题 I'm currently working on creating a shared lib DLL but I need to load it at runtime in a 64 bit environment so it currently doesn't work. How can I compile 64bit dlls from code blocks using g++ ? I've tried compiler options like -m64 but none seem to work. 回答1: To compile 64-bit programs on windows using g++, you need MinGW64. I believe that Code::Blocks comes with MinGW32. To install it onto Code::Blocks, extract the zip file to a folder without spaces, such as C:\MinGW64 Open Code::Blocks

Should templated functions take lambda arguments by value or by rvalue reference?

China☆狼群 提交于 2019-12-17 18:15:38
问题 GCC 4.7 in C++11 mode is letting me define a function taking a lambda two different ways: // by value template<class FunctorT> void foo(FunctorT f) { /* stuff */ } And: // by r-value reference template<class FunctorT> void foo(FunctorT&& f) { /* stuff */ } But not: // by reference template<class FunctorT> void foo(FunctorT& f) { /* stuff */ } I know that I can un-template the functions and just take std::functions instead, but foo is small and inline and I'd like to give the compiler the best

Linker returns “relocation has an invalid symbol at symbol index…”

房东的猫 提交于 2019-12-17 17:38:36
问题 I am trying out some code on Ubuntu. I'm trying to run the following code #include <cstdlib> #include <cmath> #include <ctime> #include "random.h" using namespace std; /* Function prototype! */ void initRandomSeed(); int randomInteger(int low,int high){ initRandomSeed(); double d= rand()/(double(RAND_MAX)+1); double s= d*(double(high)-low+1); return int(floor(low)+s); } double randomReal(int low,int high){ initRandomSeed(); double d=rand()/(double(RAND_MAX)+1); double s=d*(double(high)-low+1)

VLAs when compiling a C++ source with g++

陌路散爱 提交于 2019-12-17 17:22:32
问题 I understand that VLAs are part of C99 but not C++0x. My question is then why and how g++ would compile code with VLAs. I wrote a test case below: test.c #include "stdio.h" int main(int argc, char *argv[]) { int i; int array[argc]; for(i = 0; i < argc; i++) array[i] = i; for (i = 0; i < argc; i++) printf("%d ", i); puts(""); return 0; } I also copied it into a file called test.cpp . The following all compile: $ gcc test.c -o test // expected $ g++ test.cpp -o test // not expected $ g++ test