boost::program_options::positional_options_description termination - c++

The following program aborts with pointer being freed was not allocated:
#include <boost/program_options.hpp>
int main(int argc, char* argv[])
{
boost::program_options::positional_options_description positional;
return 0;
}
I compiled and linked the program with Boost 1.46.1, which I built myself into /usr/local, on OS X 10.6.7. I can't find any installed libboost_program_options other than the one I'm (supposedly) linking against.
Any idea what causes this crash?
Edit: As for stacktrace, the program
#include <boost/program_options.hpp>
#include <execinfo.h>
int main(int argc, char* argv[])
{
boost::program_options::positional_options_description positional;
void* callstack[128];
int i, frames = backtrace(callstack, 128);
char** strs = backtrace_symbols(callstack, frames);
for (i = 0; i < frames; ++i) {
printf("%s\n", strs[i]);
}
free(strs);
return 0;
}
built as
g++ -Wp,-MMD,.make-debug/main.dd -Wall -g3 -I/usr/local/include -c main.cc -o .make-debug/main.o
g++ -o sandbox .make-debug/main.o -lboost_program_options -L/usr/local/lib
and run as ./sandbox produces the output
0 sandbox 0x00000001000017bf main + 57
1 sandbox 0x0000000100001764 start + 52
2 ??? 0x0000000000000001 0x0 + 1
sandbox(50587) malloc: *** error for object 0x7fff70506500: pointer being freed was not al
located
*** set a breakpoint in malloc_error_break to debug
Command terminated
As for building Boost:
$ cd boost_1_46_1
$ ./bootstrap.sh --prefix=/usr/local
$ ./bjam toolset=darwin-4.2
And here's my ~/user-config.jam:
using darwin : 4.0 : g++-4.0 ;
using darwin : 4.2 : g++-4.2 ;
using darwin : 4.5.1 : /Users/matan/usr/bin/g++ ;

I am unable to reproduce
macmini:stackoverflow samm$ cat po.cc
#include <boost/program_options.hpp>
#include <boost/version.hpp>
#include <iostream>
int
main(int argc, char* argv[])
{
std::cout << BOOST_LIB_VERSION << std::endl;
boost::program_options::positional_options_description positional;
return 0;
}
macmini:stackoverflow samm$ g++ -I /opt/local/include -L/opt/local/lib -lboost_program_options po.cc
macmini:stackoverflow samm$ ./a.out
1_46_1
macmini:stackoverflow samm$
you should update your question with the steps you used to build boost, particularly the arguments to bjam.

I think I resolved the issue, but I'm not happy with my solution. I neglected to mention that I previously installed gcc 4.6.0 with --program-suffix=-4.6 in /usr/local. Uninstalling it and rebuilding Boost solved the issue. I then had no compilers installed other than gcc-4.0 and gcc-4.2 which came with XCode. Presumably gcc-4.6 files interfered with gcc-4.0 files or the darwin toolset.

Related

Intel OpenCL only detecting the nvidia platform

I just installed the intel opencl sdk on ubuntu 15.10. I am trying to use it and for some reason I am only able to detect the nvidia opencl platform.
#include <CL/cl.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
cl_uint nids;
clGetPlatformIDs(0, NULL, &nids);
printf("Platforms = %d\n", nids);
cl_platform_id* plat_ids = malloc(sizeof(cl_platform_id) * nids);
clGetPlatformIDs(nids, plat_ids, NULL);
for(int i = 0; i < nids; i++)
{
char name[1000];
clGetPlatformInfo(plat_ids[i], CL_PLATFORM_VENDOR, 1000, name, NULL);
puts(name);
}
return 0;
}
This code outputs...
Platforms = 1
NVIDIA Corporation
This seems strange to me because I am not even linking with the nvidia libOpenCL.so. Here is my compile command from eclipse
make all
Building file: ../main.c
Invoking: GCC C Compiler
gcc -I/opt/intel/intel-opencl-1.2-6.0.0.1049/opencl-1.2-sdk-6.0.0.1049/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.o" -o "main.o" "../main.c"
Finished building: ../main.c
Building target: OpenCLTest
Invoking: GCC C Linker
gcc -L/opt/intel/intel-opencl-1.2-6.0.0.1049/opencl-1.2-6.0.0.1049/lib64 -o "OpenCLTest" ./main.o -lOpenCL
Finished building target: OpenCLTest
As you can see I only link with the Intel library.

c++ hello world throws Segmentation fault - MinGW, Netbeans

Set up MinGW and Netbeans. Only working withe othere IDE's and compilers in before. My machine is x64 win7x64. I'm not shure if I only installed the 32bit version of MinGW.
Compiling a simpel Helle World in x64 leeds to:
g++ -m64 -c -g -MMD -MP -MF "build/Debug/MinGW-Windows/main.o.d"
-o build/Debug/MinGW-Windows/main.o main.cpp
//Message: sorry, unimplemented: 64-bit mode not compiled in
The win32 Version compiles fine.
// ---
g++ -m32 -c -g -MMD -MP -MF "build/Debug/MinGW-Windows/main.o.d"
-o build/Debug/MinGW-Windows/main.o main.cpp
// Compiles without any error...
Starting the 32-Version it prints only one message and terminats withe a segmentation fault before returning from first std:cout. Using ftream, to make a file output same error occures.
The demo-Programm of netbeans "Welcome" throws the same exceptions.
#include <cstdlib>
#include <iostream> // EDIT! (worked at this post long time sry.)
using namespace std;
int main(int argc, char** argv) {
int i = 0; // for making shure, program is working before calling fs.open
std::cout << "hello world blubb" << endl; // this one shows up its message at consol.
//programm aborded.
std::cout << "Now again" << endl; // this on is never reached.
return 0;
}
Errormessages:
Signal received: SIGSEGV ( Segmentation fault )
For programm cppapplication_1 pid 7972
You may discard...
Errormessage windows:
cppapplication_1.exe does not work.
Where can I start my serach? Compiler? some dlls? Dependency Walker?
Thx for any comment =).
Cutton

How to link to shared lib in c++

Could someone help me with linking to a shared lib, specifically libzmq, in C++?
all: clean compile
clean:
rm bin *.o -f
compile:
g++ -g -Wall -I/usr/local/include -L/usr/local/lib main.cpp -lzmq -o bin
I've installed libzmq using the following steps:
git clone https://github.com/zeromq/libzmq.git
cd libzmq
./autogen.sh
./configure
make && sudo make install
Here's my main.cpp
#include <iostream>
#include <string>
#include <zmq/zmq.h>
// Required by fork routine
#include <sys/types.h>
#include <unistd.h>
// Required by wait routine
#include <sys/wait.h>
#include <stdlib.h> // Declaration for exit()
#include <cstdio> // printf
using namespace std;
int global_variable = 2;
int main(int argc, char** argv){
const short int FORK_FAILED = -1;
const short int FORK_SUCCESS = 0;
int stack_variable = 20;
pid_t pid;
string status_identifier;
switch (pid = fork()){
case FORK_SUCCESS:
printf("Child changing global and stack variables\n");
global_variable++;
stack_variable++;
break;
case FORK_FAILED:
cerr << "Failed! -- Failed to fork: " << pid << endl;
exit(1);
default:
printf("Child process (pid=%d) created successfully.\n", pid);
wait(0);
break;
}
printf("[pid=%d] Global: %d\n", pid, global_variable);
printf("[pid=%d] Stack: %d\n", pid, stack_variable);
return 0;
}
And, here's the error msg:
bitcycle # ubuntu64vm ~/git/test $ make
rm bin *.o -f
g++ -g -Wall -I/usr/local/include -L/usr/local/lib main.cpp -lzmq -o bin
main.cpp:4:23: fatal error: zmq/zmq.hpp: No such file or directory
compilation terminated.
make: *** [compile] Error 1
The error is pretty straight forward, but I've yet to find a solution. Any ideas?
My goal is to do something like this with multiple child processes.
Update I'm just going to install it system-wide in ubuntu: sudo apt-get install libzmq-dev, and that resolved the issue. It doesn't teach me anything about how to identify a shared lib and header file on disk and link to it... but I guess I can move that to another day.
C++ wrapper for ZeroMQ (zmq.hpp) is no longer part of ZeroMQ. There is no zmq.hpp in current libzmq master or in latest stable 3.2.x.

How do I statically link SDL to my a.out on Linux (Ubuntu)

Let's take this snippet:
#include "SDL/SDL.h"
int main( int argc, char* args[] )
{
SDL_Init( SDL_INIT_EVERYTHING );
SDL_Quit();
return 0;
}
Compile command would be:
g++ -o myprogram mysource.cpp -lSDL
How can I 'include' SDL in my executable so that another enduser can execute it at once (without installing SDL or even recompiling my source) ?
Try:
g++ -o myprogram mysource.cpp -Wl,-Bstatic \
$(sdl-config --static-libs) -Wl,-Bdynamic

Error when running program with sharing library

There is such code:
#include <cstdlib>
#include <clang-c/Index.h>
using namespace std;
int main(int argc, char** argv)
{
CXIndex Index = clang_createIndex(0, 0);
CXTranslationUnit TU = clang_parseTranslationUnit(Index, 0, argv, argc, 0, 0, CXTranslationUnit_None);
for (unsigned I = 0, N = clang_getNumDiagnostics(TU); I != N; ++I)
{
CXDiagnostic Diag = clang_getDiagnostic(TU, I);
CXString String = clang_formatDiagnostic(Diag,
clang_defaultDiagnosticDisplayOptions());
fprintf(stderr, "%s\n", clang_getCString(String));
clang_disposeString(String);
}
clang_disposeTranslationUnit(TU);
clang_disposeIndex(Index);
return 0;
}
And it's compiled with following flags:
g++ main.cpp -g -fno-rtti `llvm-config --cxxflags --ldflags --libs` -lclang -o main
However when I want to run main:
./main
then there is following error:
./main: error while loading shared libraries: libclang.so: cannot open shared object file: No such file or directory
However:
$ sudo find / -name libclang.so
/usr/local/lib/libclang.so
Library seems to be on place. How to run this program?
ldconfig creates the necessary links and cache to the most recent
shared libraries found in the directories specified on the command
line, in the file /etc/ld.so.conf, and in the trusted directories
(/lib and /usr/lib)
Try running /sbin/ldconfig and then if that doesn't work try appending the file /etc/ld.so.conf with "/usr/local/lib" and then run /sbin/ldconfig
Commands:
Run the following command and then try compiling/running again
/sbin/ldconfig
If that doesn't work then do this and then try compiling/running again
echo "/usr/local/lib" >> /etc/ld.so.conf
/sbin/ldconfig