GithubHelp home page GithubHelp logo

Comments (12)

franko avatar franko commented on August 24, 2024

Hello,

did you try adding -fPIC in CFLAGS and CXXFLAGS in Makefile ? Maybe the this flag is mandatory on x86_64 ?

from graph-toolkit.

markuman avatar markuman commented on August 24, 2024
$ cat makeconfig 
# set this to "yes" if you want to disable gamma correction
DISABLE_GAMMA_CORR = no

# set this to "yes" if you want to disable subpixel LCD antialiasing
DISABLE_SUBPIXEL_LCD = no

DEBUG = no

VERSION = 1.0

PREFIX = /usr
DEST_DIR =

CFLAGS = "-fPIC"
CXXFLAGS = "-fPIC"

doesn't solve the problem (Arch Linux x86_64). Same error in Ubuntu 14.04 x86_64.
Furthermore, I've noticed that libgsl0-dev is a (make)dependency too.

from graph-toolkit.

markuman avatar markuman commented on August 24, 2024

I hate makefiles ...

When I add -fPIC nearly everywhere, it seems to build it without error.

# Makefile
# 
# Copyright (C) 2009 Francesco Abbate
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#

include makeconfig

ifneq (,$(findstring Windows,$(OS)))
  HOST_SYS= Windows
else
  HOST_SYS:= $(shell uname -s)
  ifneq (,$(findstring CYGWIN,$(TARGET_SYS)))
    HOST_SYS= Windows
  endif
endif

ifeq ($(strip $(DEBUG)), yes)
  CXXFLAGS = -g -Wall
  DEFS += -LIBGRAPH_DEBUG
else
  CXXFLAGS = -Os -fno-exceptions -ffast-math -fno-rtti -Wall
endif

PTHREAD_DEFS += -D_REENTRANT
CPP_SUP_LIBS = -lsupc++

ifeq ($(strip $(DISABLE_GAMMA_CORR)), yes)
  DEFS += -DDISABLE_GAMMA_CORR
endif

ifeq ($(strip $(DISABLE_SUBPIXEL_LCD)), yes)
  DEFS += -DDISABLE_SUBPIXEL_AA
endif

ifeq ($(HOST_SYS),Windows)
  DISPLAY_SUFFIX = win32

  USER_LIBS_HOME = C:/fra/local
  USER_INCLUDE = $(USER_LIBS_HOME)/include

  INCLUDES += -I$(USER_INCLUDE) -I/usr/include -I/usr/pthreads-w32/include
  LIBS += -L$(USER_LIBS_HOME)/lib

  AGG_INCLUDES = -I$(USER_INCLUDE)/agg2
  AGG_LIBS = -lagg -lgdi32

  FREETYPE_INCLUDES = -I$(USER_INCLUDE)/freetype
  FREETYPE_LIBS = -lfreetype

  PTHREADS_LIBS = -lpthread

  LIBGRAPH_SO = graphcore.dll
  LIBNATWIN_SO = natwin.dll

  LUA_INCLUDES = -I../luajit2/src
  LUA_LIBS = -L../luajit2/src -llua51

  LDFLAGS += -Wl,--enable-auto-import
  LIBS += -L/usr/lib

  DEFS += -DWIN32
else
  X11_INCLUDES = $(shell pkg-config x11 --cflags)
  X11_LIBS = $(shell pkg-config x11 --libs)

# GWH (for OS X): pkg-config will include "-Wl,-rpath,/opt/local/lib" in AGG_LIBS.
# If you don't include that, the code won't run unless you first do:
#   export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib

  AGG_INCLUDES = $(shell pkg-config libagg --cflags)
  AGG_LIBS = $(shell pkg-config libagg --libs)

  FREETYPE_INCLUDES = $(shell pkg-config freetype2 --cflags)
  FREETYPE_LIBS = $(shell pkg-config freetype2 --libs)

  LUA_INCLUDES = $(shell pkg-config --cflags luajit)
  LUA_LIBS = $(shell pkg-config --libs luajit)

  PTHREAD_DEFS += -pthread
  PTHREAD_LIBS = -lpthread

  ifeq ($(HOST_SYS),Darwin)
    LINK_EXE = $(CXX) $(LDFLAGS)
    # Use rsync because the --parents option to cp doesn't exist in
    # Mac OS X
    CP_REL = rsync -R
    LDFLAGS += -Wl,-E
  endif

  DISPLAY_SUFFIX = x11

  LIBGRAPH_SO = libgraphcore.so
  LIBNATWIN_SO = libnatwin.so
endif

ifeq ($(strip $(DEST_DIR)), )
  DEST_PREFIX = $(PREFIX)
else
  DEST_PREFIX = $(DEST_DIR)/$(PREFIX)
endif
LUA_PATH = $(DEST_PREFIX)/share/lua/5.1
LUA_DLLPATH = $(DEST_PREFIX)/lib/lua/5.1
SYSTEM_LIBPATH = $(DEST_PREFIX)/lib
DEBIAN = debian_build/$(PREFIX)

ifeq ($(HOST_SYS),Windows)
  PLATFORM_NATWIN_SRC_FILES = agg_platform_support_win32.cpp agg_win32_bmp.cpp
  PLATFORM_PLOT_SRC_FILES = agg_win32_bmp.cpp
else
  ifeq ($(HOST_SYS),Darwin)
    DEFS += -DDARWIN_MACOSX
  endif
  PLATFORM_NATWIN_SRC_FILES = agg_platform_support_x11.cpp
endif

GRAPH_LUA_SRC = graph/init.lua graph/contour.lua

HOST_CP = cp
HOST_RM = rm -f
CP_REL = cp --parents

CC = gcc
CXX = g++

INCLUDES += $(LUA_INCLUDES) $(FREETYPE_INCLUDES) $(X11_INCLUDES) $(AGG_INCLUDES)
LIBS += $(FREETYPE_LIBS) $(AGG_LIBS) $(X11_LIBS) $(LUA_LIBS) $(PTHREAD_LIBS)
DEFS += $(PTHREAD_DEFS)

COMPILE = $(CC) $(CFLAGS) $(DEFS) $(INCLUDES)
CXXCOMPILE = $(CXX) $(CXXFLAGS) $(DEFS) $(INCLUDES)

NATWIN_CSRC_FILES =
NATWIN_CPPSRC_FILES = $(PLATFORM_NATWIN_SRC_FILES) canvas-window.cpp window.cpp

PLOT_CSRC_FILES = str.c gs-types.c lua-utils.c lua-properties.c
PLOT_CPPSRC_FILES = gamma.cpp printf_check.cpp utils.cpp window_registry.cpp fonts_search_$(DISPLAY_SUFFIX).cpp $(PLATFORM_PLOT_SRC_FILES) image_write_$(DISPLAY_SUFFIX).cpp fonts.cpp agg_font_freetype.cpp plot.cpp plot-auto.cpp units.cpp colors.cpp markers.cpp draw_svg.cpp canvas_svg.cpp lua-draw.cpp lua-text.cpp text.cpp agg-parse-trans.cpp lua-plot.cpp bitmap-plot.cpp lua-graph.cpp
PLOT_OBJ_FILES := $(PLOT_CSRC_FILES:%.c=%.o) $(PLOT_CPPSRC_FILES:%.cpp=%.o)

NATWIN_OBJ_FILES := $(NATWIN_CSRC_FILES:%.c=%.o) $(NATWIN_CPPSRC_FILES:%.cpp=%.o)

DEP_FILES := $(NATWIN_CPPSRC_FILES:%.cpp=.deps/%.P) $(NATWIN_CSRC_FILES:%.c=.deps/%.P) $(PLOT_CPPSRC_FILES:%.cpp=.deps/%.P) $(PLOT_CSRC_FILES:%.c=.deps/%.P)

DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)

TARGETS = $(LIBGRAPH_SO) $(LIBNATWIN_SO)

all: $(LIBGRAPH_SO) $(LIBNATWIN_SO)

$(LIBGRAPH_SO): $(PLOT_OBJ_FILES)
  $(CC) -fPIC -shared $(PLOT_OBJ_FILES) -o $@ $(LIBS) -lsupc++
  strip --strip-unneeded $@

$(LIBNATWIN_SO): $(NATWIN_OBJ_FILES) $(LIBGRAPH_SO)
  $(CC) -fPIC -shared $(NATWIN_OBJ_FILES) -o $@ $(LIBS) -L. -lgraphcore -lsupc++
  strip --strip-unneeded $@

install: $(TARGETS)
  mkdir -p $(LUA_PATH)
  mkdir -p $(LUA_DLLPATH)
  cp $(LIBGRAPH_SO) $(LUA_DLLPATH)/graphcore.so
  cp $(LIBNATWIN_SO) $(LUA_DLLPATH)/natwin.so
  ln -s $(LUA_DLLPATH)/graphcore.so $(SYSTEM_LIBPATH)/libgraphcore.so
  $(CP_REL) $(GRAPH_LUA_SRC) $(LUA_PATH)

debian: $(TARGETS)
  rm -fr debian_build
  rm -fr lua-graph-toolkit*.deb
  mkdir -p $(DEBIAN)/share/lua/5.1
  mkdir -p $(DEBIAN)/lib/lua/5.1
  cp $(LIBGRAPH_SO) $(DEBIAN)/lib/lua/5.1/graphcore.so
  cp $(LIBNATWIN_SO) $(DEBIAN)/lib/lua/5.1/natwin.so
  ln -s lua/5.1/graphcore.so $(DEBIAN)/lib/libgraphcore.so
  $(CP_REL) $(GRAPH_LUA_SRC) $(DEBIAN)/share/lua/5.1
  fakeroot bash debian/build.sh $(VERSION)

clean:
  $(HOST_RM) *.o *.so *.dll $(TARGETS)

%.o: %.cpp
  @echo Compiling $<
  @$(CXXCOMPILE) -fPIC -Wp,-MMD,.deps/$(*F).pp -c $<
  @-cp .deps/$(*F).pp .deps/$(*F).P; \
  tr ' ' '\012' < .deps/$(*F).pp \
          | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
            >> .deps/$(*F).P; \
  rm .deps/$(*F).pp

%.o: %.c
  @echo Compiling $<
  @$(COMPILE) -fPIC -Wp,-MMD,.deps/$(*F).pp -c $<
  @-cp .deps/$(*F).pp .deps/$(*F).P; \
  tr ' ' '\012' < .deps/$(*F).pp \
          | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
            >> .deps/$(*F).P; \
  rm .deps/$(*F).pp

.PHONY: debian clean all

-include $(DEP_FILES)

from graph-toolkit.

markuman avatar markuman commented on August 24, 2024

Ok, figured it out. Only line 196 needs the -fPIC option.

from graph-toolkit.

franko avatar franko commented on August 24, 2024

Ok. I would try to fix that in the git repository, may be tomorrow. May be I can even understand why the -fPIC flag is needed and where :-)

Thank you for looking at that in any case and sorry for the Makefile ;-)

from graph-toolkit.

markuman avatar markuman commented on August 24, 2024

No problem ;)

But after compiling it creates graphcore.so which isn't found by lua (it is looking for graph.so when running require "graph"). require "graphcore" works, but using local p = graphcore.fxplot(f, 0, 25) than failed.

So after all, I'm not sure where and what the probem it atm.

from graph-toolkit.

franko avatar franko commented on August 24, 2024

Well, at least for this problem I know what is going on.

The "graph" module is supposed to work only after "make install" and will not
work locally from the compilation directory.

The idea is that the "graph" module is initialized using the "graph/init.lua"
file. This file, in turns load the two shared library "graphcore" and "natwin".

The problems when trying to running without make install are:

  • in package.path "./?/init.lua" is not included
  • the "natwin.so" shared library is dinamically linked to "libgraphcore.so" so
    this latter should be available (with the "lib" prefix) in the system library
    directory.

Normally the "make install" does copy the files in the good place and create a
few symlinks. Otherwise there is a "make debian" target to create a debian
package but I have hardcoded "i386" as the architecture :-) May be you can
fix that to create a valid debian package for the x86_64.

It is possible to make the module works locally but it is a little bit tricky
especially because you have to ensure that natwin.so can be dynamically linked
to libgraphcore.so. Tipically this involve to configure LD_LIBRARY_PATH and is
not straightforward.

May be the best option is to do a "make install" or create a package using the
"make debian" rule already existing.

from graph-toolkit.

markuman avatar markuman commented on August 24, 2024

Even when I do a dirty # make install it failed

$ lua5.1 
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> require "graph"
/usr/share/lua/5.1/graph/init.lua:2: module 'bit' not found:
  no field package.preload['bit']
  no file './bit.lua'
  no file '/usr/share/lua/5.1/bit.lua'
  no file '/usr/share/lua/5.1/bit/init.lua'
  no file '/usr/lib/lua/5.1/bit.lua'
  no file '/usr/lib/lua/5.1/bit/init.lua'
  no file './bit.so'
  no file '/usr/lib/lua/5.1/bit.so'
  no file '/usr/lib/lua/5.1/loadall.so'
stack traceback:
  [C]: in function 'require'
  /usr/share/lua/5.1/graph/init.lua:2: in main chunk
  [C]: in function 'require'
  stdin:1: in main chunk
  [C]: ?

Furthermore, the makefile failed in an Arch Linux PKGBUILD too. Dunno what the problem is...

$ makepkg 
==> Making package: graph-toolkit-git 20141016-1 (Thu Oct 16 19:39:50 CEST 2014)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
  -> Updating graph-toolkit git repo...
Fetching origin
==> Validating source files with md5sums...
    graph-toolkit ... Skipped
==> Extracting sources...
  -> Creating working copy of graph-toolkit git repo...
Cloning into 'graph-toolkit'...
done.
==> Starting prepare()...
==> Removing existing pkg/ directory...
==> Starting build()...
Compiling str.c
Compiling gs-types.c
Compiling lua-utils.c
Compiling lua-properties.c
Compiling gamma.cpp
Compiling printf_check.cpp
Compiling utils.cpp
Compiling window_registry.cpp
Compiling fonts_search_x11.cpp
Compiling image_write_x11.cpp
Compiling fonts.cpp
Compiling agg_font_freetype.cpp
Compiling plot.cpp
plot.cpp: In member function 'double plot::draw_axis_m(plot::axis_e, units&, const agg::trans_affine&, ptr_list<draw::text>&, double, agg::path_storage&, agg::path_storage&)':
plot.cpp:198:22: warning: '*((void*)(& bb)+8).agg::rect_base<double>::y2' may be used uninitialized in this function [-Wmaybe-uninitialized]
     opt_rect<double> bb;
                      ^
plot.cpp:198:22: warning: '*((void*)(& bb)+8).agg::rect_base<double>::x2' may be used uninitialized in this function [-Wmaybe-uninitialized]
plot.cpp:198:22: warning: '*((void*)(& bb)+8).agg::rect_base<double>::y1' may be used uninitialized in this function [-Wmaybe-uninitialized]
plot.cpp:198:22: warning: '*((void*)(& bb)+8).agg::rect_base<double>::x1' may be used uninitialized in this function [-Wmaybe-uninitialized]
Compiling plot-auto.cpp
Compiling units.cpp
Compiling colors.cpp
Compiling markers.cpp
Compiling draw_svg.cpp
Compiling canvas_svg.cpp
Compiling lua-draw.cpp
Compiling lua-text.cpp
Compiling text.cpp
Compiling agg-parse-trans.cpp
Compiling lua-plot.cpp
lua-plot.cpp: In function 'int plot_get_legend(lua_State*)':
lua-plot.cpp:832:27: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
     lua_rawgeti(L, -1, pos);  /* push leg_table[pos] */
                           ^
lua-plot.cpp: In function 'int plot_set_legend(lua_State*)':
lua-plot.cpp:799:27: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
     lua_rawseti(L, -2, pos);  /* leg_table[pos] = legend */
                           ^
lua-plot.cpp:774:26: note: 'pos' was declared here
     sg_plot::placement_e pos;
                          ^
Compiling bitmap-plot.cpp
Compiling lua-graph.cpp
Compiling agg_platform_support_x11.cpp
Compiling canvas-window.cpp
Compiling window.cpp
gcc -shared str.o gs-types.o lua-utils.o lua-properties.o gamma.o printf_check.o utils.o window_registry.o fonts_search_x11.o image_write_x11.o fonts.o agg_font_freetype.o plot.o plot-auto.o units.o colors.o markers.o draw_svg.o canvas_svg.o lua-draw.o lua-text.o text.o agg-parse-trans.o lua-plot.o bitmap-plot.o lua-graph.o -o libgraphcore.so -lfreetype  -lagg  -lX11  -lluajit-5.1  -lpthread -lsupc++
strip --strip-unneeded libgraphcore.so
gcc -shared  agg_platform_support_x11.o canvas-window.o window.o -o libnatwin.so -lfreetype  -lagg  -lX11  -lluajit-5.1  -lpthread -L. -lgraphcore -lsupc++
strip --strip-unneeded libnatwin.so
==> Entering fakeroot environment...
==> Starting package()...
mkdir -p /usr/share/lua/5.1
mkdir -p /usr/lib/lua/5.1
cp libgraphcore.so /usr/lib/lua/5.1/graphcore.so
cp: cannot create regular file '/usr/lib/lua/5.1/graphcore.so': Permission denied
Makefile:173: recipe for target 'install' failed
make: *** [install] Error 1
==> ERROR: A failure occurred in package().
    Aborting...

from graph-toolkit.

markuman avatar markuman commented on August 24, 2024

Well, it seems partly to work with luajit

$ luajit
LuaJIT 2.0.3 -- Copyright (C) 2005-2014 Mike Pall. http://luajit.org/
JIT: ON CMOV SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc sink fuse
> require "graph"
> 
local function f(x) return math.sin(x) * x^2 end> 
> local p = graph.fxplot(f, 0, 25)
warning:    /usr/share/lua/5.1/graph/init.lua:62: attempt to call upvalue 'f' (a nil value)
warning:    /usr/share/lua/5.1/graph/init.lua:62: attempt to call upvalue 'f' (a nil value)
...
warning:    /usr/share/lua/5.1/graph/init.lua:62: attempt to call upvalue 'f' (a nil value)
warning:    /usr/share/lua/5.1/graph/init.lua:62: attempt to call upvalue 'f' (a nil value)
> p.xtitle = "x axis"
p.title = "y = sin(x) * x^2"stdin:1: attempt to index global 'p' (a nil value)
stack traceback:
  stdin:1: in main chunk
  [C]: at 0x00404710
> 

In lua5.1 the same. The previous error is gone when installing lua51-bitop.

And this is a quick&dirty PKGBUILD for Arch Linux ...which seems not to work correctly yet...

pkgname=graph-toolkit-git
_pkgname=graph-toolkit
pkgver=20141016
pkgrel=1
pkgdesc="Lua graph-toolkit"
arch=('i686' 'x86_64')
license=('BSD Licence')
depends=('gsl' 'agg' 'lua51-bitop')
makedepends=('git' 'libxft' 'freetype2')
url="https://github.com/franko/graph-toolkit"
source=('graph-toolkit::git+git://github.com/franko/graph-toolkit.git')
md5sums=('SKIP')

prepare() {
  cd "$srcdir/$_pkgname"
  sed -i 's/@$(CXXCOMPILE)/@$(CXXCOMPILE) -fPIC/' Makefile
  echo 'CFLAGS = "-fPIC"' >> makeconfig
  echo 'CXXFLAGS = "-fPIC"' >> makeconfig
  sed -i 's/DEST_DIR\ =/DEST_DIR\ =\ "$pkgdir"/' makeconfig

}

build() {
  cd "$srcdir/$_pkgname"
  make
}

package() {
  cd "$srcdir/$_pkgname"
  make DESTDIR="$pkgdir" install
}

from graph-toolkit.

franko avatar franko commented on August 24, 2024

Hi,

it seems that now is ok. The error you got attempt to call upvalue 'f' (a nil value) is due to the fact the you declared the function f as a local function. In the REPL this doesn't work because every line is considered a separate chunk. You should try instead to declare the function f without the local keyword. The snippet is supposed to work only you write it in a fine and execute it with dofile.

About Lua vs LuaJIT, I didn't actually test the module with Lua itself but only with LuaJIT. If the bitop module is enough to make it work this is a good news.

The permission error on ARCH seems to be a permission issue but I'm not able to tell more about the exact reason.

from graph-toolkit.

markuman avatar markuman commented on August 24, 2024

Ah ok, works fine without local - even in lua 5.1. when lua51-bitop is installed.

I try to make a working Arch Linux PKGBUILD next days

from graph-toolkit.

franko avatar franko commented on August 24, 2024

Great! :-) Thank you.

from graph-toolkit.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.