Check GCC version using Eclipse - c++

I try to get my gcc version using below code.
when I build and run it ,
console show "Nothing to build fro (my project name) ".
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main( int argc, char ** argv ) {
stringstream version;
version << "GCC version: "
<< __GNUC__ << "." << __GNUC_MINOR__ << "." << __GNUC_PATCHLEVEL__
<< "\nVersion string: " << __VERSION__;
cout << version.str() << endl;
return 0;
}

I found the solution.
I didn't set path variable to MinGW.
I it working properly.
Thank you all.

Related

missing output in the eclipse console when debugging

I recently started using Eclipse CDT (version 2019-03) with the Cygwin toolchain and have noticed some bizarre behaviour when using the debugger.
Under the debugger the following program behaves as you would expect
#include <iostream>
int main()
{
std::cout << "hello world\n" << std::flush;
}
However the following produces no output
#include <iostream>
int main()
{
std::cout << "* world\n" << std::flush;
}
And for the following the output is world
#include <iostream>
int main()
{
std::cout << "# world\n" << std::flush;
}
This behaviour is completely consistent and reproduceable. Does anyone have any explanation or workarounds?

when i use the c++ string in my code it compiles but i don't show an output

I don't know whether I have installed cygwin wrong or what but the code compiles fine but it doesn't show the output. Here's my code:
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
string name;
cout << "Enter the name of the person" << endl;
getline(cin, name);
cout << "Name is: " << name << endl;
return 0;
}
Here's the compilation image and the execution:
Your code is fine. The correct way to call the executable using Cygwin is ./string.exe
As I can see, you use cygwin. I had the same issue with gcc 5.2. Try to install gcc 4.9 and all corresponding libraries for this version instead.

res->getString(1) mysql connector crash debug

I have a problem when i use mysql connector c++ and visual studio on the debug mode. It compiles just fine. My algorithm works on release mode. When i switch to debug mode, he complies but he crash while running.
I believe that he crash each time i use res->getString() .
I m using visual studio 2013, mysql connector.C++ 1.1 . I already added the dependencies
C:\Program Files\MySQL\Connector.C++ 1.1\lib\debug
C:\Program Files\Boost SDK;
C:\Program Files\MySQL\Connector.C++ 1.1\include
mysqlcppconn.lib and mysqlcppconn.dll
CPPCONN_PUBLIC_FUNC= ;HAVE_INT8_T=1 ( on the processor definition)
run time library : /MDd ( it the only think that works )
I copied mysqlcppconn.lib and mysqlcppconn.dll in the debug directory of my project
with this configuration my programm works on release mode ( changing Connector.C++ 1.1\lib\debug to Connector.C++ 1.1\lib\opt ).
In the debug mode, he says Debug Assertion failed :
File: f:\dd\vctools\crt\crtw32\misc\dbgheap.c
Line 1322
Expression : _CrtIsValidHeapPointer( pUserData)
Press Rety to debug the application
then i had to choose one buttom ( Ignore; Restart ; leave ). When i press Ignore he continue to run i have the first results but he crashs again
This is my code section
{
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <memory>
#include <string>
/* MySQL Connector/C++ specific headers */
#include <cppconn/driver.h>
#include <cppconn/connection.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
#include <cppconn/resultset.h>
#include <cppconn/metadata.h>
#include <cppconn/resultset_metadata.h>
#include <cppconn/exception.h>
#include <cppconn/warning.h>
#include "mysql_connection.h"
using namespace std;
using namespace sql;
int main(int argc, const char **argv)
{
const char* str_DataBaseMarketData_Server = "root";
const char* str_DataBaseMarketData_User = "root";
const char* str_DataBaseMarketData_Password ="root";
const char* str_DataBaseMarketData_Database ="bd test";
cout << "Connector/C++ tutorial framework..." << endl;
cout << endl;
string fld;
try {
sql::Driver* driver = get_driver_instance();
std::auto_ptr<sql::Connection> con(driver->connect(str_DataBaseMarketData_Server, str_DataBaseMarketData_User, str_DataBaseMarketData_Password));
con->setSchema(str_DataBaseMarketData_Database);
std::auto_ptr<sql::Statement> stmt(con->createStatement());
sql::SQLString *data = new SQLString();
std::auto_ptr<sql::ResultSet> res(stmt->executeQuery("SELECT * FROM news "));
//ResultSetMetaData *res_meta = res->getMetaData();
//cout << res_meta->getColumnDisplaySize( 1) << endl << endl;
while (res->next()){
fld = res->getString(2).c_str();
}
}
catch (sql::SQLException &e) {
/*
The MySQL Connector/C++ throws three different exceptions:
- sql::MethodNotImplementedException (derived from sql::SQLException)
- sql::InvalidArgumentException (derived from sql::SQLException)
- sql::SQLException (derived from std::runtime_error)
*/
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
/* Use what() (derived from std::runtime_error) to fetch the error message */
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
return EXIT_FAILURE;
}
cout << "Done." << endl;
return EXIT_SUCCESS;
}
}
This things turns me crazy because when i replace getString() by anything else, it works sweetly.Could you help me please ?
I m running under a 32 bit.

Building and using Log4cplus with CMake

community,
I have the following problem with building and using the Log4cplus library with Embarcadero.
First, I download the library from http://sourceforge.net/p/log4cplus/wiki/Home/, then I navigate to a Directory where I want to build my library, and type cmake -G "Borland Makefiles" mypathtotherootomypreviousdownload. It then says, the build files have been written to the current directory.
Now I start the MSYS sh.exe and type make. This does also work. I get a bin Folder with various working tests (as exe files) of the library. In this bin folder there is also a dll log4cplusUD.dll. Now I also find in a src folder the corresponding LIB log4cplusUD.lib.
I am of course familiar how you can statically link a dynamic library with Embarcadero. But on attempting to compile
#pragma hdrstop
#pragma argsused
#ifdef _WIN32
#include <tchar.h>
#else
typedef char _TCHAR;
#define _tmain main
#endif
#include <stdio.h>
#include "log4cplus/logger.h"
#include "log4cplus/consoleappender.h"
#include "log4cplus/loglevel.h"
#include <log4cplus/loggingmacros.h>
#include <iomanip>
using namespace std;
using namespace log4cplus;
int _tmain(int argc, _TCHAR* argv[])
{
log4cplus::initialize ();
SharedAppenderPtr append_1(new ConsoleAppender());
append_1->setName(LOG4CPLUS_TEXT("First"));
Logger::getRoot().addAppender(append_1);
Logger root = Logger::getRoot();
Logger test = Logger::getInstance(LOG4CPLUS_TEXT("test"));
LOG4CPLUS_DEBUG(root,
"This is"
<< " a reall"
<< "y long message." << endl
<< "Just testing it out" << endl
<< "What do you think?");
test.setLogLevel(NOT_SET_LOG_LEVEL);
LOG4CPLUS_DEBUG(test, "This is a bool: " << true);
LOG4CPLUS_INFO(test, "This is a char: " << 'x');
LOG4CPLUS_INFO(test, "This is a short: " << static_cast<short>(-100));
LOG4CPLUS_INFO(test, "This is a unsigned short: "
<< static_cast<unsigned short>(100));
LOG4CPLUS_INFO(test, "This is a int: " << 1000);
LOG4CPLUS_INFO(test, "This is a unsigned int: " << 1000u);
LOG4CPLUS_INFO(test, "This is a long(hex): " << hex << 100000000l);
LOG4CPLUS_INFO(test, "This is a unsigned long: " << 100000000ul);
LOG4CPLUS_WARN(test, "This is a float: " << 1.2345f);
LOG4CPLUS_ERROR(test,
"This is a double: "
<< setprecision(15)
<< 1.2345234234);
LOG4CPLUS_FATAL(test,
"This is a long double: "
<< setprecision(15)
<< 123452342342.25L);
LOG4CPLUS_WARN(test, "The following message is empty:");
LOG4CPLUS_WARN(test, "");
return 0;
}
I get a linker error,
not resolved external Symbol log4cplus::Logger::getInstance.
The code above is just one of the tests that compiled and run well, when running make from sh.exe.
So what am I doing wrong?
I also tried to link the above main.cpp againts log4cplusUD.lib with the following CMakeLists.txt file
cmake_minimum_required (VERSION 2.6)
project (log4cplustest)
include_directories("C:/Users/fin/Software/log4cplus-1.2.0-rc3/log4cplus-1.2.0-rc3/include")
add_executable(log4cplustest main.cpp)
target_link_libraries(log4cplustest log4cplusUD)
but I get the same Linker error!

mkdir() returns -1 when launched through Finder

I have a simple program that makes a directory when it is executed:
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main(){
if(int a = mkdir("abc",0700)){
std::cout << "Failed to create: " << a << std::endl;
}
else{
std::cout << "Created." << std::endl;
}
}
It behaves differently for two different use cases:
Running the compiled binary through Terminal
Output: Created.
Launching this program via Finder with double click.
Output: Failed to create: -1
How do I make this so that launching this program via Finder creates the folder abc without using Cocoa framework (compiles with g++ only)?
Thanks to Wooble for pointing it out in the comment section that the problem is due to the working directory. When I launched it through Finder, the current working directory was my home directory.
Below is how I address the problem:
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <libproc.h>
int main(int argc, char** argv){
// Gets and prints out the current directory
char cwd[1024];
getcwd(cwd, sizeof(cwd));
std::cout << "Current Working Directory: " << cwd << std::endl;
// Above is not necessary
// Changes working directory to directory that contains executable
char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
if(proc_pidpath (getpid(), pathbuf, sizeof(pathbuf)) > 0){ // Gets the executable path
std::string s(pathbuf);
s = s.substr(0,s.find_last_of('/')); // Removes executable name from path
std::cout << "Executable Path: " << s << std::endl;
chdir(s.c_str()); // Changes working directory
}
if(int a = mkdir("abc",0700)){
std::cout << "Failed to create: " << a << std::endl;
}
else{
std::cout << "Created." << std::endl;
}
}