Problem with wxWidgets on Snow Leopard - c++

I have a problem with getting compiled an wxWidget-application. I have installed the latest version of the library as follows:
set arch_flags="-arch x86_64 "
./configure -with-osx_cocoa --disable-shared --disable-compat24 --enable-unicode --enable-universal-binary CFLAGS="$arch_flags" CXXFLAGS="$arch_flags" CPPFLAGS="$arch_flags" LDFLAGS="$arch_flags" OBJCFLAGS="$arch_flags" OBJCXXFLAGS="$arch_flags"
sudo make install
I'am trying to compile a simple hello-world example with:
WXWIDGETS = -I/usr/local/include/wx-2.9/
CXXFLAGS = -O2 -g -Wall -Wextra -fmessage-length=0
CXX = $(shell wx-config --cxx)
PROGRAM = wxProjectExample
OBJECTS = $(PROGRAM).o
# implementation
.SUFFIXES: .o .cpp
.cpp.o :
$(CXX) -c `wx-config --static=yes --libs` `wx-config --static=yes --cxxflags` -o $# $<
all: $(PROGRAM)
$(PROGRAM): $(OBJECTS)
$(CXX) -o $(PROGRAM) $(OBJECTS) `wx-config --libs`
clean:
rm -f *.o $(PROGRAM)
But the compilation fails while linking with:
ld: warning: in /System/Library/Frameworks//QuickTime.framework/QuickTime, missing required architecture x86_64 in file
ld: warning: in /usr/lib/libwx_macud-2.8.dylib, missing required architecture x86_64 in file
Undefined symbols:
"wxWindowBase::DoSetVirtualSize(int, int)", referenced from:
vtable for MyFramein wxProjectExample.o
Where could be a problem or have somebody had similar problems with this framework?
Thx.
PS
System: SnowLeopard (64 bit) 10.6.5. with an intel proc, gcc 4.2.

i fixed this problem by adding the path to the new wx-binaries to PATH
$ export PATH=/usr/local/Cellar/wxmac/2.8.11/bin:$PATH
i'm using brew to install wxmac.

I'm surprised that you have libwx_xxx in /usr/lib when the default installation prefix is /usr/local. Are you sure you don't have multiple incompatible libraries versions on your system?
Also, when using static linking the libraries containing the dependencies of your code must come after the object file referencing them so the wx-config --libs part should be at the end of your rule.

Related

Igraph makevars will not link to static library, i can use data structures but cannot functions while importing igraph c++ library

I am trying to install my C++ igraph library from https://github.com/igraph/igraph to visual studio code using the following method this is my makefile made according to this link.
CXX = g++
CXX_FLAGS = -std=c++17 -O3 -march=native -DNDEBUG
LIB = -Llib
INC = -Iinclude
.PHONY: all
all: a.out
a.out: main.cpp
$(CXX) $(CXX_FLAGS) $(INC) $(LIB) -ligraph -lm -lstdc++ -lgomp -lpthread -o $# main.cpp
.PHONY: clean
clean:
rm a.out
The compiler will always return something like:
g++ -std=c++17 -O3 -march=native -DNDEBUG -Iinclude -Llib -ligraph -lm -lstdc++ -lgomp -lpthread -o a.out main.cpp
/usr/bin/ld: /tmp/ccqJLfvi.o: in function `main':
main.cpp:(.text.startup+0x9): undefined reference to `igraph_rng_default'
/usr/bin/ld: main.cpp:(.text.startup+0x16): undefined reference to `igraph_rng_seed'
collect2: error: ld returned 1 exit status
make: *** [Makefile:12: a.out] Error 1
If i only want to use data structures such as igraph_t graph* it will work, but if i try to call fucntion it will return error and will not generate a.out file. It would be incredablly good if someone would be able to explain why this happens cuz it really got on my nerve right now.
Please follow the instructions in the documentation to set up your package to link to igraph.
Instructions to install igraph: https://igraph.org/c/html/latest/igraph-Installation.html Note that you must both build and install the package. Make a note of the location you used to install it to (the value of CMAKE_INSTALL_PREFIX)
Instructions on compiling your first igraph program: https://igraph.org/c/html/latest/igraph-Tutorial.html Unless you are already comfortable with writing C programs and linking them to external libraries, I strongly recommend that you use CMake to set up your project, as described in the linked tutorial. CMake works the same way on all platforms (Windows/macOS/Linux) and will automatically figure out how to link your program to igraph correctly. When configuring your project, be sure to set CMAKE_PREFIX_PATH to the location where you installed igraph earlier.

Error linking IRAF library relocation R_X86_64_32 against can not be used

I'm trying to compile a program called DAOSPEC written in Fortran. It gives me the following error (among similar others):
/usr/bin/ld: /home/osboxes/iraf/bin.linux64//libimfort.a(imakwc.o): relocation R_X86_64_32 against `.bss' can not be used when making a PIE object; recompile with -fPIC
See the full log here.
How do I fix it?
My Makefile
FCOMP = gfortran
FFLAGS = -Wall -Wextra -fPIC -fmax-errors=1 -O3 -march=native -ffast-math -funroll-loops
.SUFFIXES: .o .f
.f.o:
$(FCOMP) -c $(FFLAGS) $<
default : daospec
daospec: daospec.o lnxsubs.o iosubs.o mathsubs.o bothsubs.o
$(FCOMP) -o daospec daospec.o lnxsubs.o iosubs.o mathsubs.o bothsubs.o -L/usr/local/lib/ -lcfitsio -lplotsub -ldevices -lutils -L/usr/lib/x86_64-linux-gnu/ -lX11 -L/home/YOUR_USERNAME/iraf/bin.linux64/ -limfort -lsys -lvops -L/home/YOUR_USERNAME/iraf/unix/bin.linux64/ -los -lf2c -lcurl
clean:
rm -rf daospec *.o
The same Makefile works on a different PC with Ubuntu 16.04 gfortran 5.4, but breaks on Ubuntu 18.04 gfortran 7.3. In both cases the IRAF library files are the same.
I have managed to solve the problem, with help from Vladimir F. Ubuntu 18.04 uses PIE, position independent executables (source), and thus it requires libraries to be built with -fPIC option. The libraries in the official IRAF distribution that I used were not build with -fPIC, and that's what caused my errors.
Fortunately, one can now install IRAF libraries from the iraf-dev package on Ubuntu 18.04:
sudo apt-get install iraf-dev
Alternatively, one can compile IRAF from Github's iraf-community/iraf repository with -fPIC option.
Lastly, I modified the Makefile to use the new locations of IRAF library files: /usr/lib/iraf/bin/ and /usr/lib/iraf/unix/bin/.
FCOMP = gfortran
FFLAGS = -Wall -Wextra -fPIC -fmax-errors=1 -O3 -march=native -ffast-math -funroll-loops
.SUFFIXES: .o .f
.f.o:
$(FCOMP) -c $(FFLAGS) $<
default : daospec
daospec: daospec.o lnxsubs.o iosubs.o mathsubs.o bothsubs.o
$(FCOMP) -o daospec daospec.o lnxsubs.o iosubs.o mathsubs.o bothsubs.o -L/usr/local/lib/ -lcfitsio -lplotsub -ldevices -lutils -L/usr/lib/x86_64-linux-gnu/ -lX11 -L/usr/lib/iraf/bin/ -limfort -lsys -lvops -L/usr/lib/iraf/unix/bin/ -los -lf2c -lcurl
clean:
rm -rf daospec *.o

how to create dylibs that link to boost

I am using clang and boost 1.57 on OSX Yosemite. I am trying to create a dylib for a python application (used swig to make the wrappers). I have successfully compiled this code for Windows and Linux, so I know it is the build/link phase on OSX that is causing me issues. Here is my makefile (which is wrong, somehow):
CC=clang++
vpath %.c ./
vpath %.h ./
SRCS=RecorderLib.cpp RecorderLib_wrap.cpp
OBJS=$(SRCS:.cpp=.o)
LIBS= -lpython2.7 -lboost_iostreams-mt -lboost_system-mt -lboost_thread-mt -lboost_date_time-mt -lboost_chrono-mt -lboost\
_filesystem-mt -lboost_regex-mt -lboost_atomic-mt -lboost_serialization-mt -lboost_program_options-mt
CFLAGS=-arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -pipe -O2 -c -stdlib=libstdc++
LINKFLAGS = -dynamiclib -undefined suppress -flat_namespace
.PHONY: RecorderLib64.dylib
all: RecorderLib_wrap.o RecorderLib.o RecorderLib64.dylib
RecorderLib_wrap.o:
$(CC) RecorderLib_wrap.cpp $(CFLAGS) $(LIBS) -o RecorderLib_wrap.o
RecorderLib.o:
$(CC) RecorderLib.cpp $(CFLAGS) $(LIBS) -o RecorderLib.o
RecorderLib64.dylib:
$(CC) $(LINKFLAGS) $(OBJS) $(LIBS) \
-o RecorderLib64.dylib
mv RecorderLib64.dylib ../../
clean:
rm *.o
If I remove the -undefined suppress -flat_namespace flags, the thing will toss me a million symbol not found for architecture x86_64 errors for all the boost functions that I reference.
When I include those flags, the library compiles but when I fire up the host application I get an error such as
OSError: dlopen(/Users/myself/RecorderApp/src/RecorderLib64.dylib, 6): Symbol not found: __ZN5boost9iostreams15file_descriptor4seekElSt12_Ios_Seekdir
which I interpret to mean the dylib doesn't know about boost.
One other thing that I don't understand, but is possibly related, is that when I compile the source objects, it tosses me errors such as:
clang: warning: -lpython2.7: 'linker' input unused
On linux, you want to link to libraries both at the compile stage and the link stage (at least this is my understanding -- in any case my Makefile.gnu which I am basing this off of does this and works beautifully).
I should also mention that I can compile applications on this system that link to boost and various dylibs and they work perfectly, so I know my boost installation etc. is alright. Also, inspecting the libraries I link to with the file command tells me they are of the correct x86_64 architecture.
Later:
So, I realize now that the symbol(s) not found for architecture x86_64 errors were actually pointing to functions in the stdlib (but were referenced from boost), i.e.:
"std::basic_streambuf<char, std::char_traits<char> >::setbuf(char*, long)", referenced from:
vtable for boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_sink, std::char_traits<char>, std::allocator<char>, boost::iostreams::output> in RecorderLib.o
Changing the makefile so that the min osx version is 10.7 and using -stdlib=libc++ gets rid of all theses errors, but I am still getting symbol(s) not found for a boost:iostreams call:
"boost::iostreams::file_descriptor::seek(long,std::__1::ios_base::seekdir)"

Issue Linking Box2D application on OS X

I have an SDL game I have been working on as my first somewhat real project. I decided to introduce Box2D physics as I was not happy with the collision detection. So I installed it to /usr/local/lib/Box2D and in the folder is Box2D.h and supporting folders. I am using MacVim to code on OSX 10.9.2 to develop, and clang++ compiler from the command line.
In my game code I am just trying to create a simple world to test things out:
#include <Box2D/Box2D.h>
.......
world = new b2World(b2Vec2(0.0,9.81));
My make command finds the library, but errors out trying to build.
$ make clean && make
rm -rf obj bin
clang++ -Wall -c -std=c++11 -I/usr/local/lib src/Ball.cpp -o obj/Ball.o
clang++ -Wall -c -std=c++11 -I/usr/local/lib src/Game.cpp -o obj/Game.o
clang++ -Wall -c -std=c++11 -I/usr/local/lib src/Paddle.cpp -o obj/Paddle.o
clang++ -Wall -c -std=c++11 -I/usr/local/lib src/TextureManager.cpp -o obj/TextureManager.o
clang++ -Wall -c -std=c++11 -I/usr/local/lib src/main.cpp -o obj/main.o
clang++ -framework SDL2 -framework SDL2_image -F /Library/Frameworks -L/usr/local/lib/Box2D obj/Ball.o obj/Game.o obj/Paddle.o obj/TextureManager.o obj/main.o -o bin/game
Undefined symbols for architecture x86_64:
"b2World::b2World(b2Vec2 const&)", referenced from:
Game::init() in Game.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [game] Error 1
And here is my Makefile. Box2D is in /usr/local/lib/Box2D/Box2D.h. I am pretty sure my issue is somewhere in the Makefile.
CXX = clang++
CXXFLAGS = -Wall -c -std=c++11 -I/usr/local/lib
SDL = -framework SDL2 -framework SDL2_image
LDFLAGS = $(SDL) -F /Library/Frameworks -L/usr/local/lib/Box2D
SRC_DIR = src
SOURCES = $(wildcard $(SRC_DIR)/*.cpp)
OBJ_DIR = obj
OBJECTS = $(subst $(SRC_DIR)/, $(OBJ_DIR)/, $(patsubst %.cpp, %.o, $(SOURCES)))
#$(warning $(OBJECTS))
BIN_DIR = bin
EXE = game
# run these no matter what
.PHONY: all clean run
all: $(EXE)
$(EXE): $(OBJECTS)
#mkdir -p $(BIN_DIR)
$(CXX) $(LDFLAGS) $(OBJECTS) -o $(BIN_DIR)/$(EXE)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
#mkdir -p $(OBJ_DIR)
$(CXX) $(CXXFLAGS) $< -o $#
clean:
rm -rf obj bin
run:
./$(BIN_DIR)/$(EXE)
It does not appear that you ever actually link the Box2D library anywhere? You use -L to specify directories to search while linking, but I don't see a -l option to actually link the Box2D library (whatever it's called).
Your output line seems to bear this out:
clang++ -framework SDL2 -framework SDL2_image -F /Library/Frameworks -L/usr/local/lib/Box2D obj/Ball.o obj/Game.o obj/Paddle.o obj/TextureManager.o obj/main.o -o bin/game
You need to get -lbox2d (or whatever the correct name for the Box2D library is) in there.

Ubuntu 12.10 - Cannot find -ltcl when I compile my C++ program

I am working on a C++ project and I need to use libtcl.
I am running Ubuntu 12.10 32bits and there is a problem when I try to compile my files :
g++ -o executable executable.o -L/usr/share/tcltk -lncurses -ltcl
/usr/bin/ld: cannot find -ltcl
libncurses is found but not libtcl...
Do you have any idea?
I have seen that libtcl8.4.so.0 libtcl8.5.so.0 exist in /usr/lib
The makefile that I am using looks like this :
CC = g++
CFLAGS = -g
LDFLAGS =
EXEC = executable
LIB = -L/usr/share/tcltk -lncurses -ltcl
all: executable
executable: executable.o
$(CC) $(LDFLAGS) -o $(EXEC) executable.o $(LIB)
executable.o: executable.cpp
$(CC) $(CFLAGS) -c executable.cpp
clean:
rm -f executable executable.o
Thanks
(Answered in a comment. See Question with no answers, but issue solved in the comments (or extended in chat) )
#soon wrote:
just create symlink to the your library like so #ln -s /usr/lib/libtcl8.5.so.0 /usr/lib/libtcl.so