Curses Development Kit - DSO missing from command line - gcc

I am trying to compile the following on Ubuntu 14.04 but am receiving an error. Can anyone point me in the right direction? I have tried -lpthread which has no effect.
Compile:
gcc main.c -o terminal-app -lcdk -lpthread
main.c (copy pasted from here save for the <cdk/cdk.h> correction)
#include <cdk/cdk.h>
void main()
{
CDKSCREEN *cdkscreen;
CDKLABEL *demo;
WINDOW *screen;
char *mesg[4];
/* Initialize the Cdk screen. */
screen = initscr();
cdkscreen = initCDKScreen (screen);
/* Start CDK Colors */
initCDKColor();
/* Set the labels up. */
mesg[0] = "</31>This line should have a yellow foreground and a cyan background.<!31>";
mesg[1] = "</05>This line should have a white foreground and a blue background.<!05>";
mesg[2] = "</26>This line should have a yellow foreground and a red background.<!26>";
mesg[3] = "<C>This line should be set to whatever the screen default is.";
/* Declare the labels. */
demo = newCDKLabel (cdkscreen, CENTER, CENTER, mesg, 4, TRUE, TRUE);
/* Draw the label */
drawCDKLabel (demo, TRUE);
waitCDKLabel (demo, ' ');
/* Clean up */
destroyCDKLabel (demo);
destroyCDKScreen (cdkscreen);
endCDK();
exit (0);
}
Error:
/usr/bin/ld: /tmp/ccUtj1kg.o: undefined reference to symbol 'initscr'
//lib/x86_64-linux-gnu/libncurses.so.5: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

Obviously, cdk requires ncurses to be directly supplied in command line. On my machine your test passes with:
gcc test.c -lcdk -lncurses

I use a makefile for compiling CDK in Linux (Debian Stable)
http://mrflash818.geophile.net/software/nc_834v5010generator/makefile
The parts I needed were two:
where to find the header files
CXXFLAGS := -Wall -g -I /usr/include/cdk
to link the CDK library
LDLIBS := -lcdk

Related

Linking guile to Rcpp

I am trying to link guile to an Rcpp file. It seems like things compile but there is an error when loading:
sourceCpp("test_2.cpp", rebuild = TRUE, showOutput = TRUE)
/usr/lib/R/bin/R CMD SHLIB --preclean -o 'sourceCpp_2.so' 'test_2.cpp'
g++-10 -I"/usr/share/R/include" -DNDEBUG -I"/home/matias/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include" -I"/home/matias/Documentos/Program/R/guile" -fpic -O3 -march=native -mtune=native -fPIC -pthread -I"/usr/include/guile/3.0" -c test_2.cpp -o test_2.o
g++-10 -shared -L/usr/lib/R/lib -lm -ldl -lgmpxx -lgmp -lmpfr -lmpc -lguile-3.0 -lgc -o sourceCpp_2.so test_2.o -L/usr/lib/R/lib -lR
Error in dyn.load("/tmp/Rtmpm2flY8/sourceCpp-x86_64-pc-linux-gnu-1.0.5/sourcecpp_29e2d33505085/sourceCpp_2.so") :
unable to load shared object '/tmp/Rtmpm2flY8/sourceCpp-x86_64-pc-linux-gnu-1.0.5/sourcecpp_29e2d33505085/sourceCpp_2.so':
/tmp/Rtmpm2flY8/sourceCpp-x86_64-pc-linux-gnu-1.0.5/sourcecpp_29e2d33505085/sourceCpp_2.so: undefined symbol: scm_init_guile
The linking works fine if I remove the Rcpp header and build directly with g++ instead.
My Makevars look like this:
CXX = g++-10
CXXFLAGS = -O3 -march=native -mtune=native -fPIC -pthread -I"/usr/include/guile/3.0"
CXXSTD = -std=c++11
LDFLAGS = -lm -ldl -lgmpxx -lgmp -lmpfr -lmpc -lguile-3.0 -lgc
The .cpp file:
#include <Rcpp.h>
#include <stdio.h>
#include <libguile.h>
using namespace Rcpp;
// [[Rcpp::export]]
int test_guile() {
SCM func, func2;
scm_init_guile();
scm_c_primitive_load("script.scm");
func = scm_variable_ref(scm_c_lookup("simple-func"));
func2 = scm_variable_ref(scm_c_lookup("quick-test"));
scm_call_0(func);
scm_call_0(func2);
return 0;
}
You are so, so close. You essentially solved this. I just took your file, made a small modification of making the script an argument and (as you didn't post script.scm) commented out the content-specific stuff. We still load it though:
#include <Rcpp.h>
#include <stdio.h>
#include <libguile.h>
using namespace Rcpp;
// [[Rcpp::export]]
int test_guile(std::string file) {
SCM func, func2;
scm_init_guile();
scm_c_primitive_load(file.c_str());
//func = scm_variable_ref(scm_c_lookup("simple-func"));
//func2 = scm_variable_ref(scm_c_lookup("quick-test"));
//scm_call_0(func);
//scm_call_0(func2);
return 0;
}
Similarly I just added a src/Makevars to the Rcpp.package.skeleton() created file. This is not good enough to ship as you need some minimal configure or alike logic to get these values from guile-config-3.0 or alike. But it passes the litmus test. C++11 is the default already under R 4.0.*, and the compiler is recent on my box anyway so we just have this (after removing a few GNU GMP and related parts we do not need):
PKG_CXXFLAGS = -I"/usr/include/guile/3.0"
PKG_LIBS = -lguile-3.0 -lgc
This now builds, installs, and runs just fine:
> file <- system.file("guile", "script.scm", package="RcppGuile")
> RcppGuile::test_guile(file)
[1] 0
>
For reference, I committed and pushed the entire example package here. If you provide a pointer to script.scm we can add that too.
Edit: A few seconds of googling leads to the script.scm you may have used so now we have a fully working example with a working embedded Guile interpreter:
> library(RcppGuile)
> test_guile(system.file("guile", "script.scm", package="RcppGuile"))
Script called, now I can change this
Adding another function, can modify without recompilation
Called this, without recompiling the C code
[1] 0
>

How to convert a GNU linker Script ld to Scatter File (ARM)

I would like to migrate from GCC to the new ARM COMPILER 6.
But I'm not able to well convert the Gnu liker script (ld) to the equivalent of ARM Scatter file.
The Original Code is as following:
arm-none-eabi-ld -T link.ld test.o shared/bootcode.o shared/vertors.o -o test.elf
Where link.ld script is as following
ENTRY(bootcode)
SECTIONS
{
. = 0x00000000;
/* Code starts with vectors, then bootcode, then other code */
.text :
{
*vectors.o(vectors)
*bootcode.o(boot)
*(.text) /* remainder of code */
} =0
.data : { *(.data) }
.bss : { *(.bss) }
/* Notes section
* This is not used so we discard it. Although not used it needs to be
* explicitly mentioned in the linker script as some toolchains will place
* the notes section at adderss 0 if it is not explicitly mentioned*/
/DISCARD/ : { *(.note*) }
}
I would like to use armlink as a linker :
armlink --cpu=8-A.32 --entry=bootcode test.o shared/bootcode.o shared/vertors.o -o test.elf --scatter=ld.scat
But I did not succeed in Creating a valid scatter File. I tried to play with the armlink options (--first, --last, --ro_base, --rw_base) but nothing went as expected (I'm getting successful compilation but the test is not working).
Any Idea on that please?
I looked at the documentation here: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0803d/pge1362065973150.html
The GNU Linker Script you want to migrate can be rewritten as:
LOAD_ROM 0x0000
{
EXEC_ROM_1 0x0000 ; Name of first exec region (EXEC_ROM_1),
; Start address for exec region (0x0000)
{
vectors.o(VECTORS)
* (InRoot$$Sections) ; All library sections that must be in a
; root region, for example, __main.o,
; __scatter*.o, __dc*.o, and * Region$$Table
}
EXEC_ROM_2 +0 ; Name of second exec region (EXEC_ROM_2)
{
bootcode.o(BOOT, +FIRST)
* (+RO)
}
SRAM +0 ; Name of third exec region (SRAM)
{
* (+RW, +ZI) ; Place all RW and ZI data into
; this exec region
}
}
In order to specify the entry point of your image you can use the command line option --entry=bootcode as you already specified in your command line.
armlink --cpu=8-A.32 --entry=bootcode test.o shared/bootcode.o shared/vertors.o -o test.elf --scatter=ld.scat
armlink allows reading of GNU LD linker script, however, with restrictions.
The flag is "--linker_script=ld_script".

Why is GCC complaining about missing identifiers before a 'sizeof' that doesn't exist?

I'm in the process of cross-compiling GTK+ 3.4.4 for Windows. I have already cross-compiled all of the build dependencies for GTK (ATK, Cairo, GDK Pixbuf, and Pango) and installed them to /usr/i686-w64-mingw32/.
Attempting to compile GTK itself, however, results in the following error:
In file included from gdkrgba.c:31:0:
fallback-c89.c:40:1: error: expected identifier or '(' before 'sizeof'
fallback-c89.c:40:1: error: expected ')' before '==' token
Line 34 - 44 of gdk/fallback-c89.c contains:
34. #ifndef HAVE_ISINF
35. /* Unfortunately MSVC does not have finite()
36. * but it does have _finite() which is the same
37. * as finite() except when x is a NaN
38. */
39. static inline gboolean
40. isinf (double x)
41. {
42. return (!_finite (x) && !_isnan (x));
43. }
44. #endif
I haven't the slightest idea where GCC is finding 'sizeof' or '=='. Why is the compiler throwing such a cryptic error message and how can I fix it?
Edit: here is the actual command line:
/usr/bin/i686-w64-mingw32-gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I..
-DG_LOG_DOMAIN="Gdk" -DGDK_COMPILATION -I.. -I../gdk -I..
-DG_DISABLE_CAST_CHECKS -mms-bitfields
-I/usr/i686-w64-mingw32/include/pango-1.0
-I/usr/i686-w64-mingw32/include/glib-2.0
-I/usr/i686-w64-mingw32/lib/glib-2.0/include
-I/usr/i686-w64-mingw32/include/cairo -I/usr/i686-w64-mingw32/include/pixman-1
-I/usr/i686-w64-mingw32/include -I/usr/i686-w64-mingw32/include/freetype2
-I/usr/i686-w64-mingw32/include/libpng15
-I/usr/i686-w64-mingw32/include/gdk-pixbuf-2.0 -O2 -Wall -mms-bitfields -MT
gdkrgba.lo -MD -MP -MF .deps/gdkrgba.Tpo -c gdkrgba.c -DDLL_EXPORT -DPIC -o
.libs/gdkrgba.o
Further edit: after compiling with the -E option, I captured the following pre-processed output... which explains the strange sizeof:
# 39 "fallback-c89.c"
static inline gboolean
((sizeof (double x) == sizeof (float) ? __fpclassifyf (double x) : sizeof double x)) == (0x0100 | 0x0400))
{
return (!_finite (x) && !_isnan (x));
}
I can only conclude that isinf is already a defined macro. It is merely being expanded when used in the function declaration above.
My question now becomes... why is HAVE_ISINF not defined? Is it a problem with the configure script?
Yet another edit: okay, so I decided to search for everything in the build tree that contained the string 'HAVE_ISINF' and came across the following instances:
autom4te.cache/traces.1
m4trace:configure.ac:740: -1- AH_OUTPUT([HAVE_ISINF], [/* Define to 1 if you
have the `isinf\' function. */
#%:#undef HAVE_ISINF])
config.h.in
/* Define to 1 if you have the `isinf' function. */
#undef HAVE_ISINF
config.h
/* Define to 1 if you have the `isinf' function. */
/* #undef HAVE_ISINF */
Surprisingly, there is nothing in config.log mentioning `HAVE_ISINF'.
(Possibly) final edit: I did some more investigation and found the string 'isinf' in autom4te.cache/output.0 here: http://paste.ubuntu.com/1154478/
This code made a reference to ac_fn_c_check_func, so I dug up the source for that function and compiled the .c sample that the script generates:
test.c:25:6: warning: conflicting types for built-in function ‘isinf’
[enabled by default]
/tmp/ccLYd1R8.o:test.c:(.text+0xc): undefined reference to `_isinf'
collect2: ld returned 1 exit status
This is odd since my explanation above would suggest that isinf is simply a macro.
I finally found this. In summary:
"The isnan() and isinf() are C99 macros not functions so use AC_CHECK_DECL instead of AC_CHECK_FUNCS for those."
So it looks like I'll be patching the source.

Undefined reference on very simple program

Once I installed Ubuntu 11.10, strange error appears. I want to use GD with my C program, so I installed package "libgd2-xpm-dev". Everything was installed - files gd.h and libgd.a are in "/usr/include" and in "/usr/lib". So, I've tried to compile simple program with GD.
#include <stdio.h>
#include <gd.h>
int main()
{
gdImagePtr im, im_clear;
int black, white;
FILE *out1;
im = gdImageCreate(100, 100);
im_clear = gdImageCreate(100, 100);
white = gdImageColorAllocate(im, 255, 255, 255);
black = gdImageColorAllocate(im, 0, 0, 0);
return 0;
}
$ gcc -lgd gd.c
/tmp/cc6LReuX.o: In function `main':
gd2.c:(.text+0x19): undefined reference to `gdImageCreate'
gd2.c:(.text+0x31): undefined reference to `gdImageCreate'
gd2.c:(.text+0x59): undefined reference to `gdImageColorAllocate'
gd2.c:(.text+0x81): undefined reference to `gdImageColorAllocate'
Wait, what? Okay, let's check something.
# Let's sure the lib was found.
$ gcc -lgd_something gd.c
/usr/bin/ld: cannot find -lgd_something
# Lets sure we made no mistake with the symbol's name
$ nm /usr/lib/libgd.a
...
00000dc0 T gdImageColorAllocate
...
000003b0 T gdImageCreate
# So, everything should be ok
$ gcc -lgd gd.c
/tmp/cc6LReuX.o: In function `main':
gd2.c:(.text+0x19): undefined reference to `gdImageCreate'
gd2.c:(.text+0x31): undefined reference to `gdImageCreate'
gd2.c:(.text+0x59): undefined reference to `gdImageColorAllocate'
gd2.c:(.text+0x81): undefined reference to `gdImageColorAllocate'
$ echo $LD_LIBRARY_PATH
# Nothing
And I don't know what shall I do. Is it an error in gcc or I do something wrong. On my previous os (Ubuntu 10.04) everything works well.
Which file should I show for you?
Change:
$ gcc -lgd gd.c
to:
$ gcc gd.c -lgd
(Reason: link order matters !)
Oh, and add -Wall while you're at it - it pains me greatly every time I see people compiling with warnings disabled.
$ gcc -Wall gd.c -lgd

Issue compiling hello world on Wt

I try to compile a hello world like application using Wt but have problems to link
I use Qt creator and mingw32 as compiler
what am I doing wrong ? Any help will be appreciated
The process "C:/MinGW32/bin/mingw32-make.exe" exited normally.
Configuration unchanged, skipping qmake step.
Starting: "C:/MinGW32/bin/mingw32-make.exe" -w
mingw32-make: Entering directory `C:/Wt/HelloWt-build-desktop'
C:/MinGW32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Wt/HelloWt-build-desktop'
g++ -c -DNDEBUG -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -D__MINGW32__ -D_WIN32 -DQT_DLL -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I'../../Qt/2010.05/qt/include/QtCore' -I'../../Qt/2010.05/qt/include/QtNetwork' -I'../../Qt/2010.05/qt/include' -I'../../Wt2/Include' -I'../../boost/include/boost-1_45' -I'../../Qt/2010.05/qt/include/ActiveQt' -I'debug' -I'../../WtTest/HelloWt' -I'.' -I'../../Qt/2010.05/qt/mkspecs/win32-g++' -o debug/main.o ../../WtTest/HelloWt/main.cpp
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -mthreads -Wl -o debug/HelloWt.exe debug/main.o -L'c:/Qt/2010.05/qt/lib' C:\Wt2\lib\libwt.a C:\Wt2\lib\libwthttp.a C:\QtSDK\mingw\lib\libws2_32.a C:\QtSDK\mingw\lib\libwsock32.a C:\boost\lib\libboost_thread-mgw45-mt-d-1_45.a C:\boost\lib\libboost_regex-mgw45-mt-d-1_45.a C:\boost\lib\libboost_date_time-mgw45-mt-d-1_45.a C:\boost\lib\libboost_signals-mgw45-mt-d-1_45.a C:\boost\lib\libboost_system-mgw45-mt-d-1_45.a C:\boost\lib\libboost_program_options-mgw45-mt-d-1_45.a C:\boost\lib\libboost_filesystem-mgw45-mt-d-1_45.a -lQtNetworkd4 -lQtCored4
mingw32-make[1]: Leaving directory `C:/Wt/HelloWt-build-desktop'
mingw32-make: Leaving directory `C:/Wt/HelloWt-build-desktop'
C:\Wt2\lib\libwthttp.a(WServer.obj): In function `WServer':
C:/wt-3.1.9/src/http/WServer.C:142: undefined reference to `Wt::WAbstractServer::instance_'
C:/wt-3.1.9/src/http/WServer.C:140: undefined reference to `Wt::WAbstractServer::~WAbstractServer()'
C:\Wt2\lib\libwthttp.a(WServer.obj): In function `~HTTPStream':
C:/wt-3.1.9/src/http/HTTPStream.h:16: undefined reference to `Wt::WebStream::~WebStream()'
C:\Wt2\lib\libwthttp.a(WServer.obj): In function `~WServer':
C:/wt-3.1.9/src/http/WServer.C:145: undefined reference to `Wt::WAbstractServer::~WAbstractServer()'
C:\Wt2\lib\libwthttp.a(WServer.obj): In function `~HTTPStream':
C:/wt-3.1.9/src/http/HTTPStream.h:16: undefined reference to `Wt::WebStream::~WebStream()'
C:\Wt2\lib\libwthttp.a(WServer.obj): In function `~WServer':
C:/wt-3.1.9/src/http/WServer.C:145: undefined reference to `Wt::WAbstractServer::~WAbstractServer()'
C:\Wt2\lib\libwthttp.a(HTTPStream.obj): In function `HTTPStream':
C:/wt-3.1.9/src/http/HTTPStream.C:17: undefined reference to `Wt::WebStream::WebStream(bool)'
C:\Wt2\lib\libwthttp.a(HTTPStream.obj): In function `~HTTPStream':
C:/wt-3.1.9/src/http/HTTPStream.h:16: undefined reference to `Wt::WebStream::~WebStream()'
C:/wt-3.1.9/src/http/HTTPStream.h:16: undefined reference to `Wt::WebStream::~WebStream()'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug/HelloWt.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "C:/MinGW32/bin/mingw32-make.exe" exited with code %2.
Error while building project HelloWt (target: Desktop)
When executing build step 'Make'
Here is the source
#include <Wt/WApplication>
#include <Wt/WBreak>
#include <Wt/WContainerWidget>
#include <Wt/WLineEdit>
#include <Wt/WPushButton>
#include <Wt/WText>
#include <boost/version.hpp>
using namespace Wt;
/*
* A simple hello world application class which demonstrates how to react
* to events, read input, and give feed-back.
*/
class HelloApplication : public WApplication
{
public:
HelloApplication(const WEnvironment& env);
private:
WLineEdit *nameEdit_;
WText *greeting_;
void greet();
};
/*
* The env argument contains information about the new session, and
* the initial request. It must be passed to the WApplication
* constructor so it is typically also an argument for your custom
* application constructor.
*/
HelloApplication::HelloApplication(const WEnvironment& env)
: WApplication(env)
{
setTitle("Hello world"); // application title
root()->addWidget(new WText("Your name, please ? ")); // show some text
nameEdit_ = new WLineEdit(root()); // allow text input
nameEdit_->setFocus(); // give focus
WPushButton *b = new WPushButton("Greet me.", root()); // create a button
b->setMargin(5, Left); // add 5 pixels margin
root()->addWidget(new WBreak()); // insert a line break
greeting_ = new WText(root()); // empty text
/*
* Connect signals with slots
*
* - simple Wt-way
*/
b->clicked().connect(this, &HelloApplication::greet);
/*
* - using an arbitrary function object (binding values with boost::bind())
*/
nameEdit_->enterPressed().connect
(boost::bind(&HelloApplication::greet, this));
}
void HelloApplication::greet()
{
/*
* Update the text, using text input into the nameEdit_ field.
*/
greeting_->setText("Hello there, " + nameEdit_->text());
}
WApplication *createApplication(const WEnvironment& env)
{
/*
* You could read information from the environment to decide whether
* the user has permission to start a new application
*/
return new HelloApplication(env);
}
int main(int argc, char **argv)
{
/*
* Your main method may set up some shared resources, but should then
* start the server application (FastCGI or httpd) that starts listening
* for requests, and handles all of the application life cycles.
*
* The last argument to WRun specifies the function that will instantiate
* new application objects. That function is executed when a new user surfs
* to the Wt application, and after the library has negotiated browser
* support. The function should return a newly instantiated application
* object.
*/
return WRun(argc, argv, &createApplication);
}
You may need to reverse the order of libwt.a and libwthttp.a on your command line. The order of arguments sometimes matters to the GNU linker.
You are trying to link you application with QtCore, QtNetwork and ActiveQt libraries, and not with Wt libraries.
As far as I can see you are unsing qmake and then make.
If you do, check you project configuration file, and compare with Hello World example of Wt used with qmake:
QT -= core
QT -= gui
TARGET = CppHelloWtQtCreatorUbuntu
LIBS += -L/usr/lib -lwt -lwthttp
QMAKE_CXXFLAGS += -DNDEBUG
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
wittyapplication.cpp
HEADERS += \
wittyapplication.h
As you can see here, all linking with Qt libraries are removed and added wt and wthttp (to have binary witch is a standalone webserver) libs.
Also make shure you have Wt header files accesible via INCLUDE enviroment variable and Wt libraries are acessibe via PATH enviroment variable.

Resources