Error in eclipse boost library - c++

I am trying to setup boost library on my eclipse. I have
Windows 7
Eclipse Luna
Boost 1.59
Mingw
I have already compile boost library with the b2 command.
I also added the library in Paths and Symbols for my project.
In the minGW linker I have the "boostdir"\stage\lib path for the -L options.
In the -l options I tried a lot of combination of
-boost_filesystem
-boost_system
-boost
-...
Here is the problem:
#include<iostream>
#include <boost/math/distributions/chi_squared.hpp>
int main() {
double pvalue = 2.667;
boost::math::chi_squared_distribution aDist(1);
pvalue = boost::math::cdf(aDist,pvalue);
std::cout << "The p-value is : "<<pvalue << std::endl;
return 0;
}
The compiler gives me :
16:24:25 **** Incremental Build of configuration Debug for project test2 ****
Info: Internal Builder is used for build
g++ "-IC:\\MinGW\\boost_1_59_0" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\test2.o" "..\\src\\test2.cpp"
..\src\test2.cpp: In function 'int main()':
..\src\test2.cpp:6:40: error: missing template arguments before 'aDist'
boost::math::chi_squared_distribution aDist(1);
^
..\src\test2.cpp:6:40: error: expected ';' before 'aDist'
..\src\test2.cpp:7:28: error: 'aDist' was not declared in this scope
pvalue = boost::math::cdf(aDist,pvalue);
^
16:24:28 Build Finished (took 3s.531ms)
The second error is ok since it is cause by line 6.
But the auto completion of eclipse works so he can somehow see the library!
Where is the error coming from?

boost::math::chi_squared_distribution is a class template. You need to provide a template parameter for it. For exampe,
boost::math::chi_squared_distribution<some_floating_point_type> mydist(1);

Related

a fatal error in compiling a c++ program

I am using eclipse kepler for C++, in compiling a simple hello world program I saw this error.
c:\mingw\include\_mingw.h:73:20: fatal error: w32api.h: No such file or directory
while the whole windows is as bellow.
09:15:59 **** Incremental Build of configuration Debug for project project1 ****
Info: Internal Builder is used for build
g++ "-IC:\\MinGW\\lib\\gcc\\mingw32\\5.3.0\\include\\c++" "-IC:\\MinGW\\lib\\gcc\\mingw32\\5.3.0\\include\\c++\\backward" "-IC:\\MinGW\\lib\\gcc\\mingw32\\5.3.0\\include" "-IC:\\MinGW\\lib\\gcc\\mingw32\\5.3.0\\include-fixed" "-IC:\\MinGW\\lib\\gcc\\mingw32\\5.3.0\\include\\c++\\mingw32" "-IC:\\MinGW\\include" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\project1.o" "..\\src\\project1.cpp"
In file included from c:\mingw\include\wchar.h:53:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\postypes.h:40,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:40,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\src\project1.cpp:2:
c:\mingw\include\_mingw.h:73:20: fatal error: w32api.h: No such file or directory
compilation terminated.
09:16:01 Build Finished (took 2s.535ms)
what can I do?
my code is this
#include <iostream>
using namespace std;
int main()
{
cout<<"hello world";
}
In my case i've solved like this:
Go to MinGW Installation Manager.
Select "Basic Setup" from installation list and tick the package "mingw32-base-bin".
From the installation tab select "Apply Changes".
the problem is related to the MinGW installer. there is a package that must be installed, but it didn't install it. go to the MinGW installer and add the ming-w32-w32.api and then apply changes from installation menu.

Eclipse C++ add shared library to main project

I´m using Eclipse 3.8.1 on Ubuntu 14.02 with 2 projects for the first time. I´m coming from c# world so that can be an Eclipse error or a C++ concept error.
testmonitor: A sample C++ project. Code:
#include <iostream>
using namespace std;
int main() {
cout << "Test program" << endl;
log_access::test();
return 0;
}
log_access is a shared library: log_access.cpp
#include <iostream>
namespace log_access {
void test()
{
std::cout << "It worked!!!" << std::endl;
}
}
I´m trying to build a shared library and link it to the main project. I went to Project -> Properties -> Project References and clicked on the project (shared lib) I want to reference.
Not worked....
Then I went to Project -> Properties -> C/C++ General -> Paths and Symbols -> References Tab and clicked on the project (shared lib) I want to reference.
Not worked...
Currently I´m getting the following error:
Invoking: GCC C++ Compiler
g++ -std:c++0x -I"home/projects/dev/sample/workspace/log_access" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/testproject.d" -MT"src/testmonitor.d" -o "src/testmonitor.o" "../src/testmonitor.cpp"
../src/testmonitor.cpp: In function 'int main()':
../src/testmonitor.cpp:34.3: error: 'log_access' has not been declared
log_access:test();
^
make: *** [src/testmonitor.o] Error 1
13:56:39 Build Finished (took 1s.246ms)
Obs: The log_access compiles fine...
I appreciate very much some help on that...
You'll need to include your definition of log_access::test in your main file via
#include "log_access.h"
Assuming you have a header file named log_access (you shouldn't include .cpp files; use them for implementing methods declared within the header file. See here for why).

How to Enable C++11 Features in Codelite

The following code compiles and runs in Xcode 5 and in Visual Studio 2013. I am interested in trying out Codelite, but Codelite will not compile the following program (a problem since I am working with scoped enums in my project). As far as I understand it, Codelite is using the same compiler as Xcode.
Is the code valid per C++11? Why is Codelite unable to compile it?
#include <iostream>
namespace abc
{
namespace xyz
{
enum class SampleEnum
{
SomeValue = 0,
SomeOtherValue = 1
};
}
}
int main(int argc, char **argv)
{
abc::xyz::SampleEnum e = abc::xyz::SampleEnum::SomeValue;
return 0;
}
Here is the build output from Codelite. In case it's garbled, it's pointing to the word "SampleEnum" in the instantiation of the variable and saying "expected a class or namespace".
/bin/sh -c 'make -j8 -e -f Makefile'
----------Building project:[ ClangTest - Debug ]----------
codelite-cc /usr/bin/clang++ -c "/Users/xxx/Desktop/Test/ClangTest/main.cpp" -g -O0 -Wall -o ./Debug/main.cpp.o -I. -I.
/Users/xxx/Desktop/Test/ClangTest/main.cpp:7:8: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions]
enum class SampleEnum
^
/Users/xxx/Desktop/Test/ClangTest/main.cpp:17:40: error: expected a class or namespace
abc::xyz::SampleEnum e = abc::xyz::SampleEnum::SomeValue;
~~~~~~~~~~^
1 warning and 1 error generated.
make[1]: *** [Debug/main.cpp.o] Error 1
make: *** [All] Error 2
2 errors, 1 warnings
It is necessary to pass -std=c++11 to the compiler to enable C++11 features. Here are the steps to do so in Codelite:
Right click on the project in the workspace view.
Select Settings near the bottom of this pop-up menu. Common Settings->Compiler->C++ Compiler Options
Click into the semicolon delimited list of compiler switches to reveal elipses and click on the elipses.
Click the checkbox for -std=c++11
If you are using C++11 extensions, compilers want it to be flagged. Without it they may throw warnings and errors. That's because some of C++11 changes are not backward-compatible, e.g. the use of auto.
For example, in gcc you should have
gcc -std=c++11
Check if your compiler shouldn't have such parameter as well!
I suppose this is because that your default std version is not c++11. To change to c++11, if you are using your terminal, you should type in the following command:
g++ yourfile.cpp -std=c++11

Eclipse c++ build error: no such file or directory

I installed MinGW and CDT following some tutorials. I'm trying to compile and run "hello world" code. There are no errors in eclipse but when I compile the code I get this error:
22:48:32 **** Incremental Build of configuration Debug for project test3 ****
Info: Internal Builder is used for build
g++ "-IC:\\MinGW\\lib\\gcc\\mingw32\\4.8.1\\include\\c++" "-IC:\\MinGW\\lib\\gcc\\mingw32\\4.8.1\\include\\c++\\mingw32" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\test3.o" "..\\src\\test3.cpp"
g++: error: CreateProcess: No such file or directory
22:48:32 Build Finished (took 135ms)
The code:
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
Might be a silly question to ask, but did you save the file somewhere before building it? I've had an error like this that was solved by saving it on my Desktop or wherever.
Edit: There seems to be several people with problems using MinGW. You mentioned you looked at previous stackoverflow questions, do they include these:
Eclipse CDT error: Unable to compile
MinGW error: No such file or directory exists
Other solutions suggest you should try compiling the program via command line, which...shouldn't be a problem since it's just "Hello, World".

Compilation error on Eclipse CDT

I have MinGW installed on my computer (I just use the one shipped with Strawberry perl). I can compile things just fine from the command line. Using Eclipse CDT, however, results in weird errors. Using the c++ hello world default project which comes with Eclipse, compilation in CDT fails with these errors:
\**** Internal Builder is used for build \****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\hw.o ..\src\hw.cpp
..\src\hw.cpp:9:20: error: iostream: No such file or directory
..\src\hw.cpp: In function 'int main()':
..\src\hw.cpp:13: error: 'cout' was not declared in this scope
..\src\hw.cpp:13: error: 'endl' was not declared in this scope
Build error occurred, build is stopped
Time consumed: 263 ms.
But when I run g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\hw.o ..\src\hw.cpp on my command line compilation goes just fine. All of the proper header files (like iostream) are in my path variable. What eclipse settings do I need to change to make this work?
Here's the file I'm trying to compile:
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
I experienced this only a few days ago, the problem turned out to be that I had both g++4.3 and g++4.4 installed and Eclipse was getting confused. I uninstalled 4.3 and the problem went away.