Project

General

Profile

Wt Compile Help

Added by Michael De Paola almost 10 years ago

I wrote a Wt application based on the charts example and everything works as it should and it runs well when I compile using make -C examples/charts from the build directory. I now want to make my code portable with its own makefile so I can check it in to a repository, and then check it out anywhere and build it.

So I made a makefile, and got the application to compile, but when I run this application (even if I move the binary to where the original charts.wt builds to in wt/build/examples/charts) it gets a segmentation fault before even reaching the first line of code (which I made a print to cerr statement to check). Also, I get build warnings that I don't get when building from the original directory.

Any insight would be appreciated. and I've put my makefile and the compile output below

Below is my makefile:

#Wt Charts application makefile
#See*** below for settings to set.
#usage: make clean
#       make all
#       make install

CXX = g++

CFLAGS += -std=c++11 -O2 -DNDEBUG -g -DREALTIME_DISABLED -I/home/user1/Downloads/git_wt/build -I/home/user1/Downloads/git_wt/src -isystem /usr/include/qt4 -isystem /usr/include/qt4/QtGui -isystem /usr/include/qt4/QtCore   

CXX_DEFINES = -DBOOST_SPIRIT_THREADSAFE -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DWT_DEPRECATED_3_0_0 -DWT_WITH_OLD_INTERNALPATH_API -D_REENTRANT


#Tool Overrides


###########################################################
#***Set Target name, Includes, Lib path and libs.
###########################################################
TARGET = chartsdim.wt
INCLUDES += ./include ../Common/include
LIBPATH += ../Common
LD2FLAGS = -Wl,-rpath=$ORIGIN/../../RealTimePlatform/SilTcpClient/:/home/user1/Downloads/git_wt/build/src/http:/home/user1/Downloads/git_wt/build/src
#Each lib should be -l<name> (omit lib prefix and extension
LIBS = -I/usr/local/include -L/usr/local/lib -L/usr/lib/ -lwthttp -lwt -lboost_regex -lboost_signals -lboost_system -lboost_thread -lboost_program_options -lboost_date_time -L../../RealTimePlatform/SilTcpClient/ -lsiltcpclient
###########################################################

CFLAGS += -fPIC -Wall $(foreach i, $(INCLUDES), -I$i)
LDFLAGS += $(foreach i, $(LIBPATH), -L$i) -shared

#Sources
OBJDIR ?= obj
SRCS := $(wildcard src/*.cpp)
OBJS := $(patsubst src/%.cpp,$(OBJDIR)/%.o,$(wildcard src/*.cpp)) 

all:  $(SRCS) $(OBJS) $(TARGET) 

$(TARGET):  $(OBJS)
    $(CXX) $(LDFLAGS) $(LD2FLAGS) $(OBJS) -o $@ $(LIBS) 

$(OBJDIR)/%.o: src/%.cpp
    $(MKDIR) $(OBJDIR)
    @echo "Compiling..."
    $(CXX) $(CXX_DEFINES) $(CFLAGS) -c $< -o $@ 

#Install should put bins under /bin and libs under /lib
install: base_setup
        cp $(TARGET) $(SILDIR)/lib

clean:
    rm -rf $(OBJDIR)
    rm -f  $(OBJS) $(TARGET)

.PHONY: all

And below is the make output:

make all
mkdir -p obj
Compiling...
g++ -DBOOST_SPIRIT_THREADSAFE -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DWT_DEPRECATED_3_0_0 -DWT_WITH_OLD_INTERNALPATH_API -D_REENTRANT -O2 -DNDEBUG -DREALTIME_ENABLED -std=c++11 -g -I/home/user1/Downloads/git_wt/build -I/home/user1/Downloads/git_wt/src -isystem /usr/include/qt4 -isystem /usr/include/qt4/QtGui -isystem /usr/include/qt4/QtCore    -fPIC -Wall  -I./include  -I../Common/include -c src/ChartConfig.cpp -o obj/ChartConfig.o 
mkdir -p obj
Compiling...
g++ -DBOOST_SPIRIT_THREADSAFE -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DWT_DEPRECATED_3_0_0 -DWT_WITH_OLD_INTERNALPATH_API -D_REENTRANT -O2 -DNDEBUG -DREALTIME_ENABLED -std=c++11 -g -I/home/user1/Downloads/git_wt/build -I/home/user1/Downloads/git_wt/src -isystem /usr/include/qt4 -isystem /usr/include/qt4/QtGui -isystem /usr/include/qt4/QtCore    -fPIC -Wall  -I./include  -I../Common/include -c src/ChartsApplication.cpp -o obj/ChartsApplication.o 
In file included from src/ChartsApplication.cpp:8:0:
src/../include/ChartsExample.h: In constructor ‘WDialogContainerClass::WDialogContainerClass(Wt::WDialog*, int, Wt::WTableView*, Wt::WPushButton*)’:
src/../include/ChartsExample.h:72:18: warning: ‘WDialogContainerClass::dialog’ will be initialized after [-Wreorder]
     Wt::WDialog *dialog;
                  ^
src/../include/ChartsExample.h:69:9: warning:   ‘int WDialogContainerClass::indexNum’ [-Wreorder]
     int indexNum;
         ^
In file included from src/ChartsApplication.cpp:8:0:
src/../include/ChartsExample.h:58:5: warning:   when initialized here [-Wreorder]
     WDialogContainerClass(Wt::WDialog *dialogIn, int indexNumIn, Wt::WTableView* dynamicTableIn, Wt::WPushButton *closeDialogButtonIn)
     ^
mkdir -p obj
Compiling...
g++ -DBOOST_SPIRIT_THREADSAFE -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DWT_DEPRECATED_3_0_0 -DWT_WITH_OLD_INTERNALPATH_API -D_REENTRANT -O2 -DNDEBUG -DREALTIME_ENABLED -std=c++11 -g -I/home/user1/Downloads/git_wt/build -I/home/user1/Downloads/git_wt/src -isystem /usr/include/qt4 -isystem /usr/include/qt4/QtGui -isystem /usr/include/qt4/QtCore    -fPIC -Wall  -I./include  -I../Common/include -c src/ChartsExample.cpp -o obj/ChartsExample.o 
In file included from src/ChartsExample.cpp:14:0:
src/../include/ChartsExample.h: In constructor ‘WDialogContainerClass::WDialogContainerClass(Wt::WDialog*, int, Wt::WTableView*, Wt::WPushButton*)’:
src/../include/ChartsExample.h:72:18: warning: ‘WDialogContainerClass::dialog’ will be initialized after [-Wreorder]
     Wt::WDialog *dialog;
                  ^
src/../include/ChartsExample.h:69:9: warning:   ‘int WDialogContainerClass::indexNum’ [-Wreorder]
     int indexNum;
         ^
In file included from src/ChartsExample.cpp:14:0:
src/../include/ChartsExample.h:58:5: warning:   when initialized here [-Wreorder]
     WDialogContainerClass(Wt::WDialog *dialogIn, int indexNumIn, Wt::WTableView* dynamicTableIn, Wt::WPushButton *closeDialogButtonIn)
     ^
src/ChartsExample.cpp: In function ‘Wt::Chart::WCartesianChart* CreateCartesianChart(Wt::WContainerWidget*, Wt::WContainerWidget*)’:
src/ChartsExample.cpp:149:23: warning: unused variable ‘x_axis’ [-Wunused-variable]
     Wt::Chart::WAxis& x_axis  = chart->axis(XAxis);
                       ^
src/ChartsExample.cpp:150:23: warning: unused variable ‘y1_axis’ [-Wunused-variable]
     Wt::Chart::WAxis& y1_axis = chart->axis(Y1Axis);
                       ^
src/ChartsExample.cpp:151:23: warning: unused variable ‘y2_axis’ [-Wunused-variable]
     Wt::Chart::WAxis& y2_axis = chart->axis(Y2Axis);
                       ^
src/ChartsExample.cpp: In function ‘void DatastoreSubstitute::fetchNewData(bool*&)’:
src/ChartsExample.cpp:303:9: warning: variable ‘i’ set but not used [-Wunused-but-set-variable]
     int i, j;
         ^
mkdir -p obj
Compiling...
g++ -DBOOST_SPIRIT_THREADSAFE -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DWT_DEPRECATED_3_0_0 -DWT_WITH_OLD_INTERNALPATH_API -D_REENTRANT -O2 -DNDEBUG -DREALTIME_ENABLED -std=c++11 -g -I/home/user1/Downloads/git_wt/build -I/home/user1/Downloads/git_wt/src -isystem /usr/include/qt4 -isystem /usr/include/qt4/QtGui -isystem /usr/include/qt4/QtCore    -fPIC -Wall  -I./include  -I../Common/include -c src/CsvUtil.cpp -o obj/CsvUtil.o 
mkdir -p obj
Compiling...
g++ -DBOOST_SPIRIT_THREADSAFE -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DWT_DEPRECATED_3_0_0 -DWT_WITH_OLD_INTERNALPATH_API -D_REENTRANT -O2 -DNDEBUG -DREALTIME_ENABLED -std=c++11 -g -I/home/user1/Downloads/git_wt/build -I/home/user1/Downloads/git_wt/src -isystem /usr/include/qt4 -isystem /usr/include/qt4/QtGui -isystem /usr/include/qt4/QtCore    -fPIC -Wall  -I./include  -I../Common/include -c src/PanelList.cpp -o obj/PanelList.o 
g++  -L../Common -shared -Wl,-rpath=RIGIN/../../RealTimePlatform/SilTcpClient/:/home/user1/Downloads/git_wt/build/src/http:/home/user1/Downloads/git_wt/build/src obj/ChartConfig.o obj/ChartsApplication.o obj/ChartsExample.o obj/CsvUtil.o obj/PanelList.o  -o chartsdim.wt -I/usr/local/include -L/usr/local/lib -L/usr/lib/ -lwthttp -lwt -lboost_regex -lboost_signals -lboost_system -lboost_thread -lboost_program_options -lboost_date_time -L../../RealTimePlatform/SilTcpClient/ -lsiltcpclient 

Replies (5)

RE: Wt Compile Help - Added by Trigve Siver almost 10 years ago

I would try to compile in the debug mode first and get the stack trace from the crash.

RE: Wt Compile Help - Added by Michael De Paola almost 10 years ago

I removed the -O2 from the makefile and put in -ggdb instead, but when I run the stack trace all I get is

Starting program: /home/user1/share/Software/SIL UI Client/chartsdimbuild/chartsdim.wt --docroot . --http-address 0.0.0.0 --http-port 8080

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000007 in ?? ()
(gdb) bt
#0  0x0000000000000007 in ?? ()
#1  0x00007fffffffe2f1 in ?? ()
#2  0x00007fffffffe336 in ?? ()
#3  0x00007fffffffe340 in ?? ()
#4  0x00007fffffffe342 in ?? ()
#5  0x00007fffffffe351 in ?? ()
#6  0x00007fffffffe359 in ?? ()
#7  0x00007fffffffe365 in ?? ()
#8  0x0000000000000000 in ?? ()

which doesn't help much

RE: Wt Compile Help - Added by Michael De Paola almost 10 years ago

To make things easier and do it one step at a time I've simplified my makefile to the below:

CXX = g++
CXXFLAGS = -Wall -g -std=c++11 -I/home/user1/Downloads/git_wt/build -I/home/user1/Downloads/git_wt/src -isystem /usr/include/qt4 -isystem /usr/include/qt4/QtGui -isystem /usr/include/qt4/QtCore
CXX_DEFINES = -DBOOST_SPIRIT_THREADSAFE -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DWT_DEPRECATED_3_0_0 -DWT_WITH_OLD_INTERNALPATH_API -D_REENTRANT
LIBS = -I/usr/local/include -L/usr/local/lib -L/usr/lib/ -lwthttp -lwt -lboost_regex -lboost_signals -lboost_system -lboost_thread -lboost_program_options -lboost_date_time -L../../RealTimePlatform/SilTcpClient/ -lsiltcpclient
LDFLAGS = -Wl,-rpath=$ORIGIN/../../RealTimePlatform/SilTcpClient/:/home/user1/Downloads/git_wt/build/src/http:/home/user1/Downloads/git_wt/build/src

chartsdim.wt: ChartConfig.o ChartsExample.o CsvUtil.o PanelList.o
    $(CXX) $(CXXFLAGS) $(CXX_DEFINES) $(LDFLAGS) src/ChartsApplication.cpp ChartConfig.o ChartsExample.o CsvUtil.o PanelList.o $(LIBS) -o chartsdim.wt 

ChartConfig.o: src/ChartConfig.cpp src/PanelList.cpp include/PanelList.h include/ChartConfig.h
    $(CXX) $(CXXFLAGS) -c src/ChartConfig.cpp 

ChartsExample.o: src/ChartsExample.cpp src/ChartConfig.cpp src/CsvUtil.cpp include/ChartsExample.h include/ChartConfig.h include/CsvUtil.h
    $(CXX) $(CXXFLAGS) -c src/ChartsExample.cpp

CsvUtil.o: src/CsvUtil.cpp include/CsvUtil.h
    $(CXX) $(CXXFLAGS) -c src/CsvUtil.cpp

PanelList.o: src/PanelList.cpp include/PanelList.h
    $(CXX) $(CXXFLAGS) -c src/PanelList.cpp

clean:
    rm -f *.o
    rm -f chartsdim.wt

and it doesn't crash on execution anymore though there's another issue somewhere else but I think I can find this one on my own.

Thanks for the help!

RE: Wt Compile Help - Added by Michael De Paola almost 10 years ago

My last issue was just due to a hardcoded array that I've been meaning to change to be dynamically allocated since a while back so my only issue that I'm unsure about was due to my original makefile. I copied that from a template and modified it so I'm not sure what I did wrong there, but the one I made from scratch had the program runnning as expected while that modified one causes a segfault immediately on execution before reaching main though I think I'll leave that mystery unsolved.

RE: Wt Compile Help - Added by Trigve Siver almost 10 years ago

I would recommend to get the symbols/(dev version of the libs/so) to be able to use stack trace in the future.

I haven't study your makefile but maybe you're mixing static/dynamic libraries and it is crashing somewhere in init code?

    (1-5/5)