I'm specifically building a test program to work on Chaiscript, which is how I encountered this issue:
chai.cpp:
#include <cstdio>
#include <iostream>
#include <chaiscript/chaiscript.hpp>
#include <chaiscript/chaiscript_stdlib.hpp>
std::string helloWorld(const std::string &t_name)
{
return "Hello " + t_name + "!";
}
int main(int argc, char** argv, char** env) {
chaiscript::ChaiScript chai;
chai.add(chaiscript::fun(&helloWorld), "helloWorld");
chai.eval("puts(helloWorld(\"Bob\"));");
return 0L;
}
/usr/lib/gcc/i686-pc-cygwin/5.4.0/../../../../i686-pc-cygwin/bin/as: CMakeFiles/chai.dir/src/chai.cpp.o: too many sections (37830)
/tmp/ccqGbeku.s: Assembler messages:
/tmp/ccqGbeku.s: Fatal error: can't write CMakeFiles/chai.dir/src/chai.cpp.o: File too big
/usr/lib/gcc/i686-pc-cygwin/5.4.0/../../../../i686-pc-cygwin/bin/as: CMakeFiles/chai.dir/src/chai.cpp.o: too many sections (37830)
This issue doesn't appear when I build on Mac or Linux.
I discovered a workaround to this issue from the Chaiscript CMakeLists.txt:
if(MINGW OR CYGWIN)
add_definitions(-O3)
endif()
Other searches on the Internet imply this big-object problem is linked the Windows executable format, and is not likely to be addressed in G++. Using MingW32 did not address this error in my case - I'm not going to 64-bit.
Object file has too many sections
Related
Based on the response to Size of file using C++17, I wrote the following program. But, when the executable is run, I get a segmentation fault. I am using g++ 8.3.0 on an iMac running High Sierra.
// c17filesize.cpp
// Jul-02-2019
#include <cstring>
#include <filesystem>
using namespace std;
int main(int argc, char **argv)
{
char filename[100];
(argc > 1) ? strcpy(filename, argv[1]) : strcpy(filename, __FILE__);
auto size = filesystem::file_size(filename);
}
Prefer using string (and its contructor) over c style strings.
according https://en.cppreference.com/w/cpp/filesystem/file_size you must specify full path. Did you verify argv[1] holds a full path?
check the file exist before attempting to read its size std::filesystem::exists(filename);
use try and catch sections to catch an exception.
Just bumped into segfault whilst using std::filesystem:exists.
With GCC 8.3. Had to link with -lstdc++fs to solve the problem.
Note: GCC 9+ solves this problem (https://gcc.gnu.org/gcc-9/changes.html)
Compiling with gcc 9.1.0 went through successfully without any qualms.
Working with DirectoryIterator example, from Poco documentation, I have some issues with it.
This is the source code:
#include "Poco/DirectoryIterator.h"
#include <iostream>
using Poco::DirectoryIterator;
using Poco::Path;
int main(int argc, char** argv) {
std::string cwd(Path::current());
DirectoryIterator it(cwd);
DirectoryIterator end;
while (it != end) {
std::cout << it.name();
if (it->isFile())
std::cout << it->getSize();
std::cout << std::endl;
Path p(it.path());
++it;
}
return 0;
}
I am using Mingw, with gcc 8.2, under Msys2 and Windows 7 (tested with Windows 10 too). Using Eclipse CDT as IDE.
When compiling in Debug mode, and run the binary, the exception "Path not found" is thrown.
When compiling in Release mode, and run the binary, it works, but the iterator "it" doesn't evolve.
It always shows "a.txt"
I am trying the example with this directory tree:
/test//a.txt
/test//b.txt
/test//test2
/test/test2/c.txt
/test/test2/d.txt
I have tested the same example in linux, and everything is working ok.
Why does it work in Linux, but not in Windows?
Any clue?
Thanks
Compiling your program, I get the next message: "Compiling POCO on Windows without #define POCO_WIN32_UTF8 is deprecated"
You need to compile with #define POCO_WIN32_UTF8.
#define POCO_WIN32_UTF8
#include "Poco/DirectoryIterator.h"
I'm trying to cross-compile on Linux for Win64 using MinGW-w64. Here's my code
#include <cstdlib>
#include <iostream>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
int main(int argc, char** argv)
{
if (argc > 1)
std::cout << std::atoi(argv[1]) << std::endl;
std::cout << boost::uuids::random_generator()() << std::endl;
return 0;
}
A simple compile fails with the error
$ x86_64-w64-mingw32-c++ hello.cpp
hello.cpp:4:31: fatal error: boost/uuid/uuid.hpp: No such file or directory
#include <boost/uuid/uuid.hpp>
^
Boost is installed in /usr/include which apparently the MinGW compiler doesn't search. If I add that path, then...
$ x86_64-w64-mingw32-c++ -I/usr/include hello.cpp
In file included from /usr/include/stdlib.h:314:0,
from /usr/x86_64-w64-mingw32/include/c++/4.9.1/cstdlib:72,
from hello.cpp:1:
/usr/include/sys/types.h:109:19: error: conflicting declaration ‘typedef __ssize_t ssize_t’
typedef __ssize_t ssize_t;
^
MinGW's cstdlib is including /usr/include/stdlib.h instead of /usr/x86_64-w64-mingw32/include/stdlib.h! How do I solve this? I need the -I in order to include Boost, but then MinGW includes other headers incorrectly.
You cannot use boost headers from /usr/include to cross-compile windows binaries.
You should also cross-compile boost.
See this guide for details about how to cross-compile boost on linux (it's for vle, but the first part is about boost):
http://www.vle-project.org/wiki/Cross_compilation_Win32
Update: Given that the guide is a little bit old, makes sense to link to boost documentation:
http://www.boost.org/boost-build2/doc/html/bbv2/tasks/crosscompile.html
I am using Ubuntu 13.10. I am getting some errors for the following code.
#include <stdlib.h>
#include <stdio.h>
#include <fstream.h>
int main(int argc, char *argv[])
{
error.set_program_name(argv[0]);
if ( argc != 2 )
{
// printf(argv[0] + " usage: fifo_client [string] \n");
/// cout << argv[0] << " usage: fifo_client [string]" << endl;
exit(EXIT_FAILURE);
}
ofstream out(fifo_file);
if(out)
out << argv[1] << endl;
return(EXIT_SUCCESS);
}
If I run the above program a.c using command
gcc a.c -o a
a.c:1:20: fatal error: iostream: No such file or directory
#include <iostream>
^
compilation terminated.
I don't know whats the problem.
Use g++ instead of gcc. gcc could compile a c++ file if it had the right extension (.cpp for instance) or with the right arguments (-x c++) but adding the arguments needed to link with the C++ libraries is far too complex to avoid the simple solution.
The problem is that you're mixing C & C++ code and compiling it using GCC.
try
#include <fstream>
using namespace std;
instead of #include <fstream.h>
anyway your source code is not full to make correct suggestion.
I ran your code in my compiler and got following error :-
test2.c:3:21: fatal error: fstream.h: No such file or directory
#include <fstream.h>
^
compilation terminated.
so i think your question has typo.
It is because you are mixing c and c++ code, fstream is part of c++. try to run by g++.
I installed Netbeans and as C++ compiler I installed cygwin. I made a simple project to test out my installation, this is the code:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
cout << "test";
return 0;
}
This is the error message that it gives: http://pastebin.com/jRRh7MPi
I hope you guys can help me out.
You need to either explicitly link to C++ standard library, or compile using g++ instead of gcc.