OpenCV, eclipse compile problem - c++

I have a compile problem I can't figure out for OpenCV2.1 in c++.
Here is a simple test code I am trying to compile:
#include <iostream>
#include "cv.h"
using namespace std;
int main() {
cout << "Hello World" << endl; // prints !!!Hello World!!!
cv::Mat mtx;
return 0;
}
I a compile error with an undefined reference as follows
**** Build of configuration Debug for project CJMVideo ****
**** Internal Builder is used for build ****
g++ -IC:\OpenCV2.1\include\opencv -IC:\Program Files\Point Grey Research\FlyCapture2\include -O0 -g3 -Wall -c -fmessage-length=0 -osrc\CJMVideo.o ..\src\CJMVideo.cpp
g++ -LC:\OpenCV2.1\lib -LC:\Program Files\Point Grey Research\FlyCapture2\lib64 -Xlinker --enable-auto-import -oCJMVideo.exe src\CJMVideo.o -lcxcore210 -lcv210 -lhighgui210 -lml210 -lFlyCapture2
src\CJMVideo.o:C:/OpenCV2.1/include/opencv/cxmat.hpp:378: undefined reference to `cv::fastFree(void*)'
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 1438 ms.
The error is C:/OpenCV2.1/include/opencv/cxmat.hpp:378: undefined reference to `cv::fastFree(void*)'
I believe I have compiled all the libraries correctly from the above command...What is the problem?
Thanks

Even though the message suggests it has not found that symbol on the OpenCV libraries, I must point out that from the command line pasted above, it seems you are trying to link your application against 64-bit compiled libraries, as indicated by -LC:\Program Files\Point Grey Research\FlyCapture2\lib64. That means you must compile OpenCV to be 64-bit too, or compile both to be 32 bits.
You are probably missing one library. On Windows, my OpenCV projects usually adds cv210.lib cvaux210.lib cxcore210.lib cxts210.lib highgui210.lib, but I use Visual Studio 2005 most of the times.

I have had problems linking cv::fastfree when the OpenCV lib was built with the intel TBB parallel library, building without TBB worked

Related

undefined reference to `WinMain' in eclipse IDE with cygwin (setup-x86_64)

I am currently doing unit testing for a project of c/c++ in eclipse IDE (Version: Luna Service Release 2 (4.4.2)) and I have recently upgraded my cygwin to cygwin64 to make it compatible with c++17 standard and my g++ version is g++ (GCC) 10.2.0, But I am not able to build my testsuites in eclipse, I have set the environment path to "C:\cygwin64\bin", But still I am getting the below error. Could you please help me with the below error:
Console output after building my project :
make all
Building file:
C:/Accurev/AngioJet_Development_ver1/CS/AngioJet/Firmware/src/ClinicalFeatures/door.cpp
Invoking: Cygwin C++ Compiler
g++ -DUNIT_TESTING - "C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../../AngioJet/Firmware/build/PicoZed_FSBL_bsp/ps7_cortexa9_0/include" -I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../testsupport/" -I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../testsupport/Source" -I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../../AngioJet/Firmware/src/Platform/Zynq7000" - I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../../AngioJet/Firmware/src/HostInterface" -I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../../AngioJet/Firmware/soup/treck/6_0_1_56/include" -I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../../Einstein/src/Platform/Zynq7000" -I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../../Einstein/src/Common" -I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../../AngioJet/Firmware/src/Common" -I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../../AngioJet/Firmware/src/ClinicalFeatures" -O0 -g -fprofile-arcs -ftest-coverage -Wall -c -fmessage-length=0 -MMD -MP -MF"src/door.d" -MT"src/door.d" -o "src/door.o" "C:/Accurev/AngioJet_Development_ver1/CS/AngioJet/Firmware/src/ClinicalFeatures/door.cpp"
Finished building: C:/Accurev/AngioJet_Development_ver1/CS/AngioJet/Firmware/src/ClinicalFeatures/door.cpp
Building target: helll.exe
Invoking: Cygwin C++ Linker
g++ -fprofile-arcs -o "helll.exe" ./src/door.o -lgcov -lbfd
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: /usr/lib/gcc/x86_64-pc-cygwin/10/../../../../lib/libcygwin.a(libcmain.o): in function `main':
/usr/src/debug/cygwin-3.3.6-1/winsup/cygwin/lib/libcmain.c:37: undefined reference to `WinMain'
collect2: error: ld returned 1 exit status
make: *** [makefile:47: helll.exe] Error 1
07:05:17 Build Finished (took 4s.531ms)
`*
I have uninstalled and reinstalled the softwares. Also I have built a new project from scratch which is building fine but whenever i try to build my project it is not building.
While doing unit testing in eclipse we create the project as c++ project and import the source files mentioned below and the structure is as follow:
Source file - door.cpp, door.h
door.h:
#include "global.h"
namespace lDOOR { void close( BasicTypes::UInt8 mode ); }
door.cpp:
#include "door.h"
void lDOOR::close(void)
{
//Normal Mode
close(BscMsg::NORMAL);
}
and we do the unit testing for the above functions present in .cpp file in the file created by us door_testsuite.h which is as follows:
#include <cxxtest/TestSuite.h>
class door_TestSuite: public CxxTest::TestSuite {
public:
void setUp(){}
void teardown(){}
void testDoorLDoorClose()
{
BscMsg::UInt8 mode = 2;
lDOOR::close(mode);
TS_ASSERT_EQUALS();
}};
And when I test the above code in cygwin terminal it executes completely fine.
This means there is no WinMain function, which is the entry point to Windows windows programs. Yes, confusing. You can choose to either build a program as a console program or windows program. (There are a few other types that are irrelevant) In a console program, the entry point is main (As with the entire world of computing), but in a windows program, it is WinMain. This question has a good answer that goes into depth about it, but you either need to switch the type of program to console, or (If your program is creating and using windows) add a WinMain function.
Sorry if this is confusing, it is difficult to differentiate between Windows, the OS, and windows, the type of program. Also, my knowledge on this subject is all from VSCode, so may be completely or partially incorrect.
TLDR: Either add a WinMain function, or switch to building your program as a windows program.

Freeglut 64 bit program linking errors

I'm trying to compile a 64 bit version of an OpenGL C++ program using freeglut. I followed the exact instructions on this website to set up freeglut with MinGW. I have the header files in C:\MinGW\include\GL, I have the 32 bit libraries in C:\MinGW\lib and 64 bit libraries in C:\MinGW\lib\x64, and I have the 64 bit freeglut.dll in my project directory. However, even the simplest of OpenGL programs don't link successfully...
My code is minimal:
// test.cpp
#include <GL/glut.h>
int main(int argc, char *argv[]) {
glutInit(&argc, argv);
}
And I compile it with the exact commands given on the readme/on the website:
g++ -c -o test.o test.cpp -I"C:\MinGW\include"
g++ -o test.exe test.o -L"C:\MinGW\lib\x64" -lfreeglut -lopengl32 -Wl,--subsystem,windows
(except of course I changed the directories and changed gcc to g++)
The compile runs fine, but linking throws these error messages:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: test.o:test.cpp:(.text+0x1c): undefined reference to `_imp____glutInitWithExit#12'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: test.o:test.cpp:(.text+0x3f): undefined reference to `_imp____glutCreateWindowWithExit#8'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: test.o:test.cpp:(.text+0x61): undefined reference to `_imp____glutCreateMenuWithExit#8'
collect2.exe: error: ld returned 1 exit status
I've tried to change -lopengl32 in the command to -lopengl64 and -lopengl, but the linker couldn't find those libraries.
I can't answer your specific case, but another approach would be to use mingw-w64, with MSYS2 as a package manager. The old mingw.org project is not well maintained, unlike mingw-w64 and the MSYS2 package database. There is probably some mismatch between how your precompiled binaries were built and the compiler you are currently using.
On my system I compiled your code with g++ -o gl gl.cpp -lfreeglut and it worked first time .
How to install MinGW-w64 and MSYS2?
Then use pacman -Ss glut to find the freeglut package.

Undefined reference to boost::random::random_device constructor and destructor on MinGW-w64 gcc

My OS is Windows 7 64-bit and C++ compiler I'm using is:
g++ (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 5.3.0
And I installed Boost version 1.60 using:
bootstrap.bat mingw
b2 install target=gcc
Then I tested is it working, using examples from Boost.Random tutorial.
With the first two everything was fine, but the third one gave linker errors about boost::random::random_device. I minimized the code to have only this:
// Compiled with:
// g++ -IC:/Boost/include/boost-1_60
// -LC:/Boost/lib -lboost_random-mgw53-mt-1_60
// main.cpp
#include "boost/random/random_device.hpp"
int main() {
boost::random::random_device rng;
}
And I get the following errors:
C:\Users\Daniel\AppData\Local\Temp\cc5DfdjZ.o:main.cpp:(.text+0x15):
undefined reference to `boost::random::random_device::random_device()'
C:\Users\Daniel\AppData\Local\Temp\cc5DfdjZ.o:main.cpp:(.text+0x20):
undefined reference to `boost::random::random_device::~random_device()'
collect2.exe: error: ld returned 1 exit status
Here, on SO, I found that someone with similar problem added -lboost_system to flags, but for me it didn't helped.
Does anyone have any idea, why it isn't working? I checked, and I have random_device.hpp header in my Boost folder, with declarations of random_device() and ~random_device() in it.
I found what was wrong - the g++ command syntax, that I wanted to use to compile and link my code.
As I wrote in my question, I do this that way:
g++ -IC:/Boost/include/boost-1_60 -LC:/Boost/lib -lboost_random-mgw53-mt-1_60 main.cpp
While the correct one is with main.cpp (or any other source code file(s), that we want to include in compiling process) before the -L and -l flags.
For example:
g++ -IC:/Boost/include/boost-1_60 main.cpp -LC:/Boost/lib -lboost_random-mgw53-mt-1_60
or even
g++ main.cpp -IC:/Boost/include/boost-1_60 -LC:/Boost/lib -lboost_random-mgw53-mt-1_60
Hope it will help anyone, who will make such silly mistake too.

Eclipse C++ on OSX Cant Build

I am new to coding and C++ and have just installed C++ and XCode on my computer. I have made Mac OSX GCC my preferred tool chain.
I can't seem to even get a simple Hello World program to run, I really need some help here, I've posted before and looked around but nothing seems to help me.
Code:
#include <iostream>
using namespace std;
int main() {
cout << "Hello world \n";
return 0;
}
Error after clicking on build all:
12:38:22 **** Incremental Build of configuration Debug for project Test1 ****
make all
Building file: ../test.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"test.d" -MT"test.o" -o "test.o" "../test.cpp"
Finished building: ../test.cpp
Building target: Test1
Invoking: MacOS X C++ Linker
g++ -o "Test1" ./test.o
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Test1] Error 1
12:38:37 Build Finished (took 15s.286ms)
You mentioned that you just installed XCode. If you are looking to get started with C++ programming, using XCode will make your experience more satisfying and learning curve faster than if you use Eclipse. XCode is a "native" IDE on Mac.
Having said this, I understand there may be reasons to use Eclipse, e.g. if you expect to start programming on non-Apple platforms in a very near future, or want to familiarize yourself with Eclipse as the IDE to do Android programming. However, if you are going to be on Mac for awhile and want to pick up C++ faster, I would strongly recommend sticking with XCode.
Now, the error you show could be because the file has not been saved, as suggested by one of the commenters. That's exactly the error you get if main() is missing.

Can't link libpqxx in MinGW

Using MSYS, I compiled libpq (from compiling postgres). I then compiled libpqxx. Now, I want to create a client that will use libpqxx. libpq seemed to work fine. And, I can compile code with libpqxx. However, linking the libpq client application fails.
Here's my code:
#include <pqxx/pqxx>
#include <iostream>
using namespace std;
using namespace pqxx;
int main() {
connection Conn("dbname=test");
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
I added a bunch of libs to the link in a vain hope it would suddenly work. Here's what I have so far:
g++ -IC:\msys\1.0\local\pgsql\include -IC:\msys\1.0\local\include -O0 -g3 -Wall -c -fmessage-length=0 -osrc\Controller.o ..\src\Controller.cpp
g++ -LC:\MinGW\lib -LC:\msys\1.0\local\pgsql\lib -LC:\msys\1.0\local\lib -oController.exe src\Controller.o -lws2_32 -lole32 -lpqxx -lpq -loleaut32 -luuid
C:\msys\1.0\local\lib/libpqxx.a(connection_base.o): In function `ZN45_GLOBAL__N__ZN4pqxx16encrypt_passwordERKSsS1_7wait_fdEibP7timeval':
C:/msys/1.0/home/rsolomon/libpqxx/libpqxx-3.0.2/src/connection_base.cxx:1434: undefined reference to `select#20'
C:\msys\1.0\local\lib/libpqxx.a(connection_base.o): In function `ZN4pqxx15connection_base12check_resultERKNS_6resultE':
C:/msys/1.0/home/rsolomon/libpqxx/libpqxx-3.0.2/src/connection_base.cxx:420: undefined reference to `select#20'
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 1770 ms.
I'm thinking the -lws2_32 should've gave me the "select#20". Why is the linker so uppity?
The Unix linker traditionally processes libraries from left to right. So it first considers ws2_32, finds that it has not much use, then goes on to pqxx, and sees that select is undefined and doesn't get defined by any of the later libraries. IOW, try moving ws2_32 to the end of the command line.