Why I can't build - c++

I just have followed the tutorials from: https://www.youtube.com/watch?v=57dbxWj7b4U
to install c++, but I can't build the project even I take the example project in eclipse: "Hello World c++ Project".The building seems successful, for exe file is generated, and concole shows
13:38:04 **** Incremental Build of configuration Release for project FirstC ****
Info: Internal Builder is used for build
g++ -O3 -Wall -c -fmessage-length=0 -o FirstProgram.o "..\\FirstProgram.cpp"
g++ -o FirstC.exe FirstProgram.o
13:38:05 Build Finished (took 1s.90ms)
But when I press "run", it says "Info: Nothing to build for TestProject", as the enclosed picture.
The system path is as following:
"c:\program files\gcc\bin;c:\program files\gcc\libexec\gcc\x86_64-pc-mingw32\5.3.0;%MINGW_HOME%\bin;%MSYS_HOME%bin;C:\Program Files (x86)\Java\jre1.8.0_25\bin;C:\ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Common Files\Autodesk Shared\;C:\Program Files (x86)\Autodesk\Backburner\;C:\Program Files\GDAL\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\nodejs\".
What will the reason probably be? I have install java several days before, and just install c++ today. Will they conflict?

"Nothing to build for TestProject" means that the project was already built before and nothing changed since then, so the project does not need to rebuild.
If you change anything in the source code, save and try again, the project should then rebuild again (once).

I have restarted the computer and now it runs well, and "hello world" comes out. I'm fooled by the system and feel so tired.....

Related

Installing opencv From Command Line (Windows)

I am trying to use opencv in a project, and am running into problems 'installing' it. I have extracted the opencv files and have created a small test program:
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
int main(int argc, char **argv){
cv::Mat im=cv::imread((argc==2)? argv[1]: "testing.jpg",1);
if (im.empty()){
std::cout << "Cannot open image." << std::endl;
} else {
cv::imshow("image",im);
cv::waitKey(0);
}
return 0;
}
To compile the program I have used the command below:
g++ -I"../../PortableGit/opt/opencv/build/include/" -L"../../PortableGit/opt/opencv/build/x64/vc15/lib" main.cpp -lopencv_core -lopencv_highgui -o main
I get the errors below:
In file included from ../../PortableGit/opt/opencv/build/include/opencv2/core.hpp:3293:0,
from ../../PortableGit/opt/opencv/build/include/opencv2/highgui.hpp:46,
from ../../PortableGit/opt/opencv/build/include/opencv2/highgui/highgui.hpp:48,
from main.cpp:1:
../../PortableGit/opt/opencv/build/include/opencv2/core/utility.hpp:714:14: error: 'recursive_mutex' in namespace 'std' does not name
a type
typedef std::recursive_mutex Mutex;
^~~~~~~~~~~~~~~
../../PortableGit/opt/opencv/build/include/opencv2/core/utility.hpp:715:25: error: 'Mutex' is not a member of 'cv'
typedef std::lock_guard<cv::Mutex> AutoLock;
^~
../../PortableGit/opt/opencv/build/include/opencv2/core/utility.hpp:715:25: error: 'Mutex' is not a member of 'cv'
../../PortableGit/opt/opencv/build/include/opencv2/core/utility.hpp:715:34: error: template argument 1 is invalid
typedef std::lock_guard<cv::Mutex> AutoLock;
I believe that it has something to do with mingw binaries no longer being included with opencv. I am missing the opencv/build/x86/mingw directory.
My questions are:
How do I 'install' opencv and use it without also installing some sort of IDE and/or CMake? (I prefer to use vim and the command line.)
Once installed, what command do I use to compile and link a program with opencv?
Any help is appreciated.
Edit:
This appears to be a problem with GCC's implementation of threads on windows. Using mingw-w64 instead of mingw fixed the std::recursive_mutex issue, but now the linker cannot find the proper files.
/i686-w64-mingw32/bin/ld.exe: cannot find -lopencv_core
/i686-w64-mingw32/bin/ld.exe: cannot find -lopencv_highgui
After quite a bit of trying things out, this is what I got to work. Oddly, following the LINUX guide to install opencv worked better than the WINDOWS guide, even though I have a windows computer.
Guide to Installing OpenCV on Windows Without VS
Heads-up: This is a multi-step process, 3 separate tools are required. Be prepared for this to take a while.
Part 1: Get everything ready
Download MinGW-w64.
On the downloads page, click on the "MinGW-w64-builds" option. Do not click on the "win-builds" option.
The reason MinGW-w64 has to be used is because it is a newer version of the MinGW compiler suit that has been improved for windows. This means that it supports the posix thread system, where as the standard MinGW compiler only supports the win32 thread system. OpenCV relies on the posix thread system, necessitating the MinGW-w64 compiler.
Extract the MinGW-w64 zip folder to a directory. In my case its PortableGit/opt/MinGW-w64
At this point, you can add the MingGW-w64/mingw32/bin folder to your path. (Assuming that this won't cause any conflicts.) If you do so, you will not have to constantly specify the g++ executable directory to run it. This is up to your discretion.
Download an opencv release.
Do not download the package for windows, click the button that says "sources"
Extract the opencv sources zip folder to a directory. In my case its PortableGit/opt/opencv-4.3.0
Also download the opencv_contrib source files directly from the repository.
Extract that folder and place it inside the top level opencv folder: PortableGit/opt/opencv-4.3.0/opencv_contrib in my case.
Download CMake.
I downloaded the zip folder, but you can download the installer if you wish.
Extract the CMake zip folder if you downloaded that, or run the installer. I put my CMake folder here: PortableGit/opt/cmake-3.17.1-win32-x86
At this point, you can add the cmake-3.17.1-win32-x86/bin folder to your path. (Assuming that this won't cause any conflicts.) If you do so, you will not have to constantly specify the cmake executable directory to run it. This is up to your discretion.
Part 2: Build OpenCV
Navigate to the opencv directory and create a build folder and cd into it.
mkdir build && cd build
Run the following export commands.
export CC=/PortableGit/MinGW-w64/mingw32/bin/gcc.exe
export CXX=/PortableGit/MinGW-w64/mingw32/bin/g++.exe
This is to make sure the next cmake command uses the proper compilers.
Run the following cmake command from within that folder:
PortableGit/opt/cmake-3.17.1-win32-x86/cmake.exe -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DOPENCV_VS_VERSIONINFO_SKIP=1 -DOPENCV_EXTRA_MODULES_PATH="/PortableGit/opt/opencv-4.3.0/opencv_contrib/modules/" ..
The -G flag specifies that we are creating build files for the MinGW compiler
The -DCMAKE_BUILD_TYPE=Release specifies that we are building the release version of opencv and not the debug version.
The DOPENCV_EXTRA_MODULES_PATH needs to be set to the modules folder inside the opencv_contrib folder. For me it was PortableGit/opt/opencv-4.3.0/opencv_contrib/modules
The DOPENCV_VS_VERSIONINFO_SKIP specifies to not include version info. If not set, the compiler will throw an error complaining about not having version files. (Shown below for reference.)
gcc: error: long: No such file or directory
mingw32-make[2]: *** [modules\core\CMakeFiles\opencv_core.dir\build.make:1341:
modules/core/CMakeFiles/opencv_core.dir/vs_version.rc.obj] Error 1
If successful, the cmake command will finish like this:
Now run this command, again from the build folder: /PortableGit/opt/MinGW-w64/mingw32/bin/mingw32-make.exe -j7
mingw32-make.exe is the windows equivalent of the Linux make command.
The -j7 option run the process with a maximum of 7 threads.
This will take a while! It took my laptop ~20 minutes to complete
If the make command ends in an error, make sure to reset your build directory before continuing any troubleshooting. This is done through this series of commands
rm -rf build
mkdir build
cd build
Part 3: Using OpenCV
To use the opencv library that you just compiled in a project of your own, compile the project with these flags from your projects main directory.
Remember that your compiler now has to be set to the mingw-w64 compiler for opencv support.
I added indentation and newlines for readability, but when entering this in the terminal do not include the newlines or indents.
The number at the end of the linker options may change depending on the version of opencv you downloaded. I downloaded opencv-4.3.0, making my number 430, but yours may be different.
PortableGit/opt/MinGW-w64/bin/g++.exe
-I../../PortableGit/opt/opencv-4.3.0/include/
-I../../PortableGit/opt/opencv-4.3.0/build/
-I../../PortableGit/opt/opencv-4.3.0/modules/core/include/
-I../../PortableGit/opt/opencv-4.3.0/modules/calib3d/include/
-I../../PortableGit/opt/opencv-4.3.0/modules/dnn/include/
-I../../PortableGit/opt/opencv-4.3.0/modules/features2d/include/
-I../../PortableGit/opt/opencv-4.3.0/modules/flann/include/
-I../../PortableGit/opt/opencv-4.3.0/modules/gapi/include/
-I../../PortableGit/opt/opencv-4.3.0/modules/highgui/include/
-I../../PortableGit/opt/opencv-4.3.0/modules/imgcodecs/include/
-I../../PortableGit/opt/opencv-4.3.0/modules/imgproc/include/
-I../../PortableGit/opt/opencv-4.3.0/modules/ml/include/
-I../../PortableGit/opt/opencv-4.3.0/modules/objdetect/include/
-I../../PortableGit/opt/opencv-4.3.0/modules/photo/include/
-I../../PortableGit/opt/opencv-4.3.0/modules/stitching/include/
-I../../PortableGit/opt/opencv-4.3.0/modules/ts/include/
-I../../PortableGit/opt/opencv-4.3.0/modules/video/include/
-I../../PortableGit/opt/opencv-4.3.0/modules/videoio/include/
-I../../PortableGit/opt/opencv-4.3.0/modules/world/include/
-L../../PortableGit/opt/opencv-4.3.0/build/lib/
*.hpp
*.cpp
-lopencv_calib3d430
-lopencv_core430
-lopencv_dnn430
-lopencv_features2d430
-lopencv_flann430
-lopencv_highgui430
-lopencv_imgcodecs430
-lopencv_imgproc430
-lopencv_ml430
-lopencv_objdetect430
-lopencv_photo430
-lopencv_stitching430
-lopencv_video430
-lopencv_videoio430
-o
main
Or you could download VS. Up to you. Hope this helps.
Correction for JackCamichael's answer
those 2 commands won't work in Windows
export CC=/PortableGit/MinGW-w64/mingw32/bin/gcc.exe
export CXX=/PortableGit/MinGW-w64/mingw32/bin/g++.exe
This should be
setx -m CC C:\msys64\mingw64\bin\gcc.exe
setx -m CXX C:\msys64\mingw64\bin\g++.exe
C:\msys64\mingw64\bin is mingw64 path on my machine

Different target names using Rust Cargo for build

Is there a way to set different target names for development and release configurations using Cargo for building? For example, rustlibd.a and rustlib.a?
No. Debug vs release information is controlled by a profile. You can see all the profile-related manifest keys in the source code. The only related one I see is rustc_options. Running the build in verbose mode, you can see how cargo calls rustc:
$ cargo build --verbose
Compiling namez v0.1.0 (file:///private/tmp/namez)
Running `rustc --crate-name namez src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=5444c772a04e08f3 -C extra-filename=-5444c772a04e08f3 --out-dir /private/tmp/namez/target/debug/deps -L dependency=/private/tmp/namez/target/debug/deps`
Finished dev [unoptimized + debuginfo] target(s) in 0.45 secs
Unfortunately, changing --crate-name does not have the effect you'd like.
Instead, I'd point out that you already have a different filename, you just have to look broader:
target/debug/libname.a
target/release/libname.a
The debug and release files are in different directories. Whatever you were going to do to move separately named libraries would have to deal with the debug and release directories anyway. Just update your script:
mv target/debug/libname.a libnamed.a
mv target/release/libname.a libname.a

Visual Studio custom build event always executing

I am using the odb compiler as a custom build tool. The build tool is always executing even though the input file is not changing.
The command line:
odb -Ic:\menuplan\src\ingredient -o c:\menuplan\src\ingredient
-d mysql --hxx-prologue "#include \"odb/traits.hxx\"" --generate-query
--generate-schema --schema-format separate
c:\menuplan\src\ingredient\ing_odb_category.hpp`
The input file is:
ing_odb_category.hpp.
The outputs:
ing_odb_category-odb.hxx;ing_odb_category-odb.ixx;ing_odb_category-odb.cxx;ing_odb_category-schema.cxx
The additional dependencies:
ing_odb_category.hpp
The description:
odb ing_odb_category.hpp
The output from Visual Studio 2010:
2>------ Build started: Project: vs_2010, Configuration: Debug Win32 ------
2> odb ing_odb_category.hpp
The odb tool takes the ing_odb_category.hpp as input and produces ing_odb_category-odb.hxx, ing_odb_category-odb.ixx,ing_odb_category-odb.cxx,ing_odb_category-schema.cxx files.
I can build the solution many times in a row and the custom build event will always run, even though the ing_odb_category.hpp file never changes.
How can I make Visual Studio only perform the custom build if the header file changes?
From the vcxproj file:
<CustomBuild Include="..\ing_odb_category.hpp">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">odb -Ic:\menuplan\src\ingredient -o c:\menuplan\src\ingredient -d mysql --hxx-prologue "#include \"odb/traits.hxx\"" --generate-query --generate-schema --schema-format separate c:\menuplan\src\ingredient\ing_odb_category.hpp</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug_Static_Unicode|Win32'">odb -Ic:\menuplan\src\ingredient -o c:\menuplan\src\ingredient -d mysql --hxx-prologue "#include \"odb/traits.hxx\"" --generate-query --generate-schema --schema-format separate c:\menuplan\src\ingredient\ing_odb_category.hpp</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">odb ing_odb_category.hpp</Message>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug_Static_Unicode|Win32'">odb ing_odb_category.hpp</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">ing_odb_category-odb.hxx;ing_odb_category-odb.ixx;ing_odb_category-odb.cxx;ing_odb_category-schema.cxx</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug_Static_Unicode|Win32'">ing_odb_category-odb.hxx;ing_odb_category-odb.ixx;ing_odb_category-odb.cxx;ing_odb_category-schema.cxx</Outputs>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">ing_odb_category.hpp</AdditionalInputs>
</CustomBuild>
Environment:
Visual Studio 2010
Windows 7 - 64bit
Visual Studio was always building the files because it said they didn't exist.
Using the Visual Studio project logging article, especially running the DebugView showed that Visual Studio was using a different path for the dependencies. I did not specify the path of the output files and dependencies, so it was trying to locate them in the default project directory.
Also, Visual Studio expects only one output file, according to Specifying Custom Build Tools article. I was supplying all the output filenames.
Summary
In the Custom Build Tool window:
There should only be one output file.
Additional output files are listed in the Additional Dependencies
slot.
All output files should be prefixed with the path of their location,
relative or absolute.
Useful build process debugging aids can be found in the Visual Studio Project Logging article, especially the DebugView application.

How to compile gSoap with ssl enabled on windows?

I am trying to build gSoap binaries with ssl support. I have downloaded the latest gSoap and binaries for WIN32 openssl from this website: http://slproweb.com/products/Win32OpenSSL.html
According to the gSoap documentation, I have to compile using the standard procedure with the DWITH_OPENSSL option enabled. I think the most natural option would be tu use minGW, but I have little experience with this tool. When I try this, (and after applying this patch I am left with two missing libraries a link time: -lssl and -lcrypto.
I guess I have to add a -L option to the compiling directive, but I dont see any libssl or libcrypto (should it be .a or .lib ?) in the openssl lib folder. Must I recompile these too or am I missing something ?
Yes, as I know if you use minGW 1st off install openssl and after that add path + flag like in followed example:
gcc -I/include/
-I/local/include
-L/local/lib
-o download_file download_file.c -llibcurl -lcurl
Here I compile basic C file.
Or if you run ./configure add flags like this:
LDFLAGS+="-L/local/lib -lcurl" LIBS+=-I/local/include ....
Ok I finally made it, here are the different steps I used :
First, I had to rebuild openssl with mingw since the static libraries are not shipped with the binaries shipped by Shining Light Production. I put the openssl folder in c:/openssl/
Then, in stdsoap2.h, I changed line 2247 to :
#if defined(WIN32) && !defined(__MINGW32__)
#define soap_strtoll _strtoi64
#else
# define soap_strtoll strtoll
#endif
#if defined(WIN32) && !defined(__MINGW32__)
# define soap_strtoull _strtoui64
#else
# define soap_strtoull strtoull
#endif
In the configure file:
I removed all occurence of -DWITH_GZIP and -lz.
I added the -lws2_32 linker option (support for winsocket I think)
Those changes in the configure file are in lines 7338-7347 :
WSDL2H_EXTRA_FLAGS="-DWITH_GNUTLS"
WSDL2H_EXTRA_LIBS="-lgnutls -lgcrypt -lgpg-error"
SAMPLE_SSL_LIBS="-lgnutls -lgcrypt -lgpg-error"
WSDL2H_SOAP_CPP_LIB="libgsoapssl++.a"
else
{ echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6; }
WSDL2H_EXTRA_FLAGS="-DWITH_OPENSSL"
WSDL2H_EXTRA_LIBS="-lssl -lcrypto -lws2_32"
SAMPLE_SSL_LIBS="-lssl -lcrypto -lws2_32"
I ran configure in mingw adding the proper LDFLAGS and CXXFLAGS, namely :
LDFLAGS+=" -L/c/openssl/ -L/c/MinGW/lib/" CXXFLAGS+=" -I/c/openssl/include/" ./configure
I ran make and crossed my finger!
You can also use a bit more "native" way, ie. Visual Studio C compiler for that. However this is not very straighforward.
First, compiling openssl (valid for VS 2015 Community Edition, but I believe any 2015 will do):
download openssl sources, unzip to some folder
download PERL for windows (either ActivePerl or Straberry Perl - this one is free) and install
open "Open Visual Studio 2015 Tools Command Prompt" from menu start
cd to openssl uncompressed source folder
Run following commands there (this set is using version w/o assembbler):
perl Configure VC-WIN32 no-asm --prefix=c:\some\openssl\dir
ms\do_ms
nmake -f ms\ntdll.mak
nmake -f ms\ntdll.mak test - optional step
nmake -f ms\ntdll.mak install
Afterwards, you get your openssl products installed in c:\some\openssl\dir
Next, to compile gSoap based application with SSL support, you have to add following settings (All settings are done from "Project->Properties" in Visual Studio):
C/C++ --> General, In Additional Include Directories, add "c:\some\openssl\dir\include" folder to the list
C/C++ --> Command Line, in the box "Additional Options", type: /DWITH_OPENSSL
Linker --> Input, Additional Dependencies: add "c:\some\openssl\dir\lib\libeay32.lib" and "c:\some\openssl\dir\lib\sskeay32.lib" to the list
If you have generated your classes using wsdl2h.exe and soapcpp2.exe tools, you are almost done.
Verify, that your stdsoap2.cpp file has those lines:
#include <openssl\ssl.h>
#include <openssl\rsa.h>
If not, you can add them just after first #ifdef WITH_OPENSSL
That was all for mine project. I could compile with VC2015 and run/debug like any other app.
Good luck.

jsoncpp on vc90?

anyone have jsoncpp working on vc90?
they use a build system, Scons, which I have never heard of. I installed the latest Scons, found an undocumented scons.bat, launched a vc90 prompt in my jsoncpp dir, modified the SConstruct file to support a msvc90 target (i copied the boilerplate from the msvc80 platform which was already supported) ran scons.bat platform=msvc90 and got errors:
scons: done reading SConscript files.
scons: Building targets ...
cl /Fobuildscons\msvc90\src\jsontestrunner\main.obj /c src\jsontestrunner\main.c
pp -GR -EHsc /nologo /MT /nologo /Iinclude /I.
main.cpp
c:\projects\docwayhead\wspt_docway_plugins\contrib\jsoncpp-src-0.5.0\include\jso
n\value.h(5) : fatal error C1083: Cannot open include file: 'string': No such fi
le or directory
scons: *** [buildscons\msvc90\src\jsontestrunner\main.obj] Error 2
scons: building terminated because of errors.
i've already put too much effort into getting this to build, and jsoncpp is clearly unmaintained, so i give up for now.
No need to use Scons.
Under the /makefiles/vc71/ you can find a visual studio solution which you can up convert and build.
Modify the msvc90 platform file to make sure VC90 include directories are used when calling cl (clearly not yet the case in the provided command line you provided).
Note that Scons is written using Python and so are its configuration files, so people who know Python around you might be able to help you efficiently, even if they know nothing about scons.
Are you sure your VS command line is working properly? I got it to work just by:
- Adding a msvc90 entry in allowed_values
- copy/pasting the msvc80 section later and modifying it to use env['MSVS_VERSION'] = 9.0
I'm using scons 1.3.0.
The scons setup for jsoncpp 0.5.0 does not support VS 9.0 or 10.0 out of the box. You need to first add msvc90 to the allowed_values in the SConstruct line 21, and the to add this section on line 103.
elif platform == 'msvc90':
env['MSVS_VERSION']='9.0'
for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
env.Tool( tool )
env['CXXFLAGS']='-GR -EHsc /nologo /MT'
Just replace 9.0 with 10.0 and 90 with 100 for VS 10.0 support.
As of version 0.6.0 of jsoncpp, you can avoid a lot of hassle by using the new Amalgamated version. This is just two .h files and one .cpp file that you compile directly into your projects. It's working great for me so far in VS 9 (and with a few mods I'm now able to compile it with C++Builder 2010 as well -- haven't really tested the result yet).
By the way, I've filed a bug against version 0.6.0-rc2; one line in the Amalgamated version of json.h needs to have a macro name changed.