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

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.

Related

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.

Add C++ Library to eclipse C++ Project

I am attempting to add an existing library to Eclipse. I use a cross compiler for C++ with the Eclipse IDE, installed on a virtual linux debian machine.
The mmapGpio lib is found here.
/mmapGpioBasicRev1.tar.gz has a cpp and an h file with a small demo program.
I have compiled this code without a problem. A .o file is generated. I've archived the file successfully with ar -q libmmapGpio.a mmapgpio.o
I've placed my libmmapGpio.a in ~/.../UserLib directory
I've placed my mmapGpio.h in ~/.../UserInclude
At this point all is OK.
I open a new project that uses the mmapGpio library:
#include "mmapGpio.h"
#include "stdio.h"
int main(void){
mmapGpio rpiGpio; // instantiate an instance of the mmapGpio class
rpiGpio.setPinDir(17,mmapGpio::OUTPUT); // set GPIO17 to output
while(1) {// toggle pin as fast as possible
rpiGpio.writePinHigh(17);
rpiGpio.writePinLow(17);
}
return 0;
}
So cross-compilation is done, but linker say cannot find -llibmapGpio!
I have made declaration in the properties project; C/C++ General
includes path : /home/octopuss/rpi/UserInclude (the mmapGpio.h file)
Library path : /home/octopuss/rpi/UserLib (the libmmapGpio.a file)
Libraries : libmmapGpio
Why do I receive this message?
for detail -> console view
03:16:30 **** Build of configuration Debug for project Gpio1 ****
make all
Building file: ../Gpio1.cpp
Invoking: Cross G++ Compiler
arm-linux-gnueabihf-g++ -I/home/octopuss/rpi/UserInclude -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Gpio1.d" -MT"Gpio1.d" -o "Gpio1.o" "../Gpio1.cpp"
Finished building: ../Gpio1.cpp
Building target: Gpio1
Invoking: Cross G++ Linker
arm-linux-gnueabihf-g++ -L/home/octopuss/rpi/UserLib -o "Gpio1" ./Gpio1.o -lmmapGpio
/home/octopuss/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: skipping incompatible /home/octopuss/rpi/UserLib/libmmapGpio.so when searching for -lmmapGpio
/home/octopuss/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lmmapGpio
collect2: error: ld returned 1 exit status
make: *** [Gpio1] Erreur 1
error :
skipping incompatible /home/.../UserLib/libmmapGpio.so when searching for -lmmapGpio
ld: cannot find -lmmapGpio
"why this message ?"
It's because with your settings, the linker actually looks up for a library file named liblibmmapGpio.a.
"... so crosscompilation is done but linker say "cannot find -llibmapGpio" !
...
- Libraries : libmmapGpio"
You just need to specify the library without the lib prefix in the linker library settings:
mmapGpio
The Eclipse CDT Builder passes this as a -l option to the linker, which automatically extends to search for libmmapGpio.a at the specified additional pathes.
See also this Q&A for more illustrated samples and links:
Problems importing libraries to my c++ project, how to fix this?
I found the problem ... my .so lib wasn't ARM cross compiled so there is a X86 library not compatible whith my ARM Programm.
I solve this to set erm-linuxgnuabihf- prefix and his path to cross setting parameter.
Thanks to TTAVAR PEI and Scott Stensland
enjoy

Eclipse: Edit toolchain (remove build step to create a shared library for CUDA)

I am trying to configure Eclipse such that it compiles a shared library in one project and uses it in another.
The problem is, that using the CUDA plugin for Eclipse one can only choose an executable generating project type.
So what I want to do is creating such a project and modify that toolchain such that Eclipse does not execute anything else than nvcc.
As you can see compiling the library is not a problem:
18:27:25 **** Incremental Build of configuration Default for project cudamath ****
make all
Building file: ../test.cu
Invoking: CUDA NVCC Compiler
nvcc --shared -Xcompiler -fPIC -o "cu_test.o" "../test.cu" && \
echo -n 'cu_test.d' ./ > 'cu_test.d' && \
nvcc -M "../test.cu" >> 'cu_test.d'
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
Finished building: ../test.cu
The problem is that Eclipse then calls g++ which is that step of the toolchain I want to cut off:
Building target: cudamath
Invoking: C++ Linker
g++ -L/opt/cuda/lib64 -o "cudamath" ./cu_test.o -lcuda -lcublas -lcudart
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
makefile:32: recipe for target 'cudamath' failed
make: *** [cudamath] Error 1
Is there a way I can do this? I've been crawling through my project settings but I can't seem to find what I'm looking for.
Here's what I did using Nsight Eclipse Edition:
File... new CUDA C/C++ project
In the next dialog, select Shared Library...Empty Project, and give the project a name (let's say it is testlib)
Finish that wizard/dialog. A new testlib project is created in the project explorer on the left
In the project explorer on the left, right click on the project name and create a new folder for your source files
Open that folder and create your new source file. For this, I selected a CUDA C/C++ source file using the CUDA bitreverse "template". This creates a new source file with the bitreverse code in it.
change int main() { in your source file to int myfunc(){
save the source file and build the project. A new libtestlib.so is successfully built.

undefined reference to `WinMain#16

I'm trying to install openCV to Eclipse C++. I installed Opencv and aded the paths and lib files but I get
**** Rebuild of configuration Debug for project test ****
**** Internal Builder is used for build ****
g++ -IC:\opencv\build\include -O0 -g3 -Wall -c -fmessage-length=0 -osrc\main.o ..\src\main.cpp
g++ -LC:\opencv\build\x86\vc10\lib -LC:\opencv\build\x86\vc11\lib -otest.exe src\main.o -lopencv_core247 -lopencv_core247d -lopencv_highgui247 -lopencv_highgui247d -lopencv_imgproc247 -lopencv_imgproc247d
C:/MinGW/i686-pc-mingw32/lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o):crt0_c.c:(.text+0x3c): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
Build error occurred, build is stopped
I know this question has been asked before but in every one of them the answer was "forgetting to include main() function". But I have a main() function and I still get this error.
Do you have any idea what should I do?
The linker probably is defaulted to use the "Windows" subsystem, which means that the main entry point is not the "main" symbol as you expect it to be, but rather "WinMain".
You can specify the subsystem of your application by passing the following argument at your g++ command line:
-Wl,-subsystem,console
(FYI, for the "Windows" subsystem, you'd use -Wl,-subsystem,windows)
You can also set this in the Eclipse project settings in the linker configuration somwhere I believe.
Basically "console", as the name suggests, creates a console-based application whose default entry-point is the main-function, the other will create a Windows GUI application whose default entry-point is the WinMain-function.
Please give it a try :)

OpenCV, eclipse compile problem

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