Setting up SystemC-AMS with Eclipse and Cygwin - Undefined Reference Error - eclipse

I installed SystemC (2.3.2) and SystemC-AMS (2.1) under Windows 7 in Cygwin without issues as follows:
./configure --with-systemc=/home/user/Workspace/systemc-2.3.2
make
make install
I then went into Eclipse (Photon - 4.8.0) and created a new C/C++ Project. For the Toolchain I chose Cygwin GCC. Furthermore, I applied the following settings to the project:
Include Paths:
"C:\cygwin64\home\user\Workspace\systemc-2.3.2\include"
"C:\cygwin64\home\user\Workspace\systemc-ams-2.1\include"
Library Search Paths:
"C:\cygwin64\home\user\Workspace\systemc-2.3.2\lib-cygwin64"
"C:\cygwin64\home\user\Workspace\systemc-ams-2.1\lib-cygwin64"
Library:
systemc
systemc-ams
Now I try to execute the following code:
#include <iostream>
#include "systemc.h"
#include "systemc-ams.h"
int sc_main (int argc, char* argv[])
{
std::cout << "Hello World" << std::endl;
sca_tdf::sca_signal <double> out1;
return 0;
}
I get an Undefined Reference error:
11:36:35 **** Incremental Build of configuration Debug for project SystemC-AMS-Test ****
make all
Building file: ../TestSCAMS.cpp
Invoking: Cygwin C++ Compiler
g++ -I"C:\cygwin64\home\user\Workspace\systemc-2.3.2\include" -I"C:\cygwin64\home\user\Workspace\systemc-ams-2.1\include" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"TestSCAMS.d" -MT"TestSCAMS.o" -o "TestSCAMS.o" "../TestSCAMS.cpp"
Finished building: ../TestSCAMS.cpp
Building target: SystemC-AMS-Test.exe
Invoking: Cygwin C++ Linker
g++ -L"C:\cygwin64\home\user\Workspace\systemc-2.3.2\lib-cygwin64" -L"C:\cygwin64\home\user\Workspace\systemc-ams-2.1\lib-cygwin64" -o "SystemC-AMS-Test.exe" ./TestSCAMS.o -lsystemc -lsystemc-ams
C:\cygwin64\home\user\Workspace\systemc-ams-2.1\lib-cygwin64/libsystemc-ams.a(convert_from_string.o):convert_from_string.cpp:(.text$_ZN8sca_util18sca_implementation18convert_by_istreamIN5sc_dt8sc_logicEEEbRT_RKSs[_ZN8sca_util18sca_implementation18convert_by_istreamIN5sc_dt8sc_logicEEEbRT_RKSs]+0x18f): undefined reference to `sc_dt::sc_logic::scan(std::istream&)'
C:\cygwin64\home\user\Workspace\systemc-ams-2.1\lib-cygwin64/libsystemc-ams.a(convert_from_string.o):convert_from_string.cpp:(.text$_ZN8sca_util18sca_implementation18convert_by_istreamIN5sc_dt8sc_logicEEEbRT_RKSs[_ZN8sca_util18sca_implementation18convert_by_istreamIN5sc_dt8sc_logicEEEbRT_RKSs]+0x18f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `sc_dt::sc_logic::scan(std::istream&)'
collect2: error: ld returned 1 exit status
make: *** [makefile:46: SystemC-AMS-Test.exe] Error 1
11:36:38 Build Failed. 1 errors, 0 warnings. (took 3s.199ms)
What could be the issue here?

On some platforms like windows, cygwin and others undefined symbols are not allowed at link stage.
The link order matters
"-lsystemc -lsystemc-ams" is not the same of " -lsystemc-ams -lsystemc"
as systemc-ams is using symbols of systemc the second version guarantees that all symbols are resolved at link stage.
It is also the reason why compiling any program the libraries invocation are at the end of the command.
gcc dummy.c -lsystemc works while gcc -lsystemc dummy.c fails with undefined symbols error

Related

Cmake fail to compile cant find python.h (Flutter, dart:ffi)

I need to connect .C/.CPP code that makes use of Python in to Flutter app.
Luckily I can use dart:ffi for it. and therefore the
but when I'm trying to compile the apk I am getting the following error:
Launching lib/main.dart on AOSP on IA Emulator in debug mode...
lib/main.dart:1
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing process /home/*usr_name*/Android/Sdk/cmake/3.18.1/bin/ninja with arguments {-C /home/*usr_name*/flutter/final4/android/app/.cxx/cmake/debug/x86_64 weather}
ninja: Entering directory `/home/*usr_name*/flutter/final4/android/app/.cxx/cmake/debug/x86_64'
[1/2] Building C object CMakeFiles/weather.dir/home/*usr_name*/flutter/final4/src/weather.c.o
FAILED: CMakeFiles/weather.dir/home/*usr_name*/flutter/final4/src/weather.c.o
/home/*usr_name*/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=x86_64-none-linux-android21 --gcc-toolchain=/home/*usr_name*/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/*usr_name*/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/sysroot -Dweather_EXPORTS -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/weather.dir/home/*usr_name*/flutter/final4/src/weather.c.o -MF CMakeFiles/weather.dir/home/*usr_name*/flutter/final4/src/weather.c.o.d -o CMakeFiles/weather.dir/home/*usr_name*/flutter/final4/src/weather.c.o -c /home/*usr_name*/flutter/final4/src/weather.c
/home/*usr_name*/flutter/final4/src/weather.c:43:10: fatal error: 'Python.h' file not found
#include <Python.h>
^~~~~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.
at first my CMakeLists.txt file looked like this:
cmake_minimum_required(VERSION 3.18)
project(py)
add_library(
weather
SHARED
../../src/weather.c
)
So I edit it to find Python and make sure that he indeed find it and the development version that I have installed :
cmake_minimum_required(VERSION 3.18)
project(py)
find_package(Python COMPONENTS Interpreter Development)
message("Python_FOUND:${Python_FOUND}")
message("Python_VERSION:${Python_VERSION}")
message("Python_Development_FOUND:${Python_Development_FOUND}")
message("Python_LIBRARIES:${Python_LIBRARIES}")
message("Python_LIBRARY_DIRS:${Python_LIBRARY_DIRS}")
message("Python_INCLUDE_DIRS:${Python_INCLUDE_DIRS}")
message("Python_LINK_OPTIONS:${Python_LINK_OPTIONS}")
message("Python_NumPy_FOUND:${Python_NumPy_FOUND}")
add_library(
weather
SHARED
../../src/weather.c
)
Now cmake . prints:
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python: /usr/bin/python3.8 (found version "3.8.10") found components: Interpreter Development Development.Module Development.Embed
Python_FOUND:TRUE
Python_VERSION:3.8.10
Python_Development_FOUND:TRUE
Python_LIBRARIES:/usr/lib/x86_64-linux-gnu/libpython3.8.so
Python_LIBRARY_DIRS:/usr/lib/x86_64-linux-gnu
Python_INCLUDE_DIRS:/usr/include/python3.8
Python_LINK_OPTIONS:
Python_NumPy_FOUND:FALSE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/*usr_name*/flutter/final4/android/app
Great, now Cmake knows where python is but still returns the same error when trying to create the apk.
I tried as well to include the include/python3.8 path for the compiler with the -I flag but that caused a bunch of different issues that make me force outer paths which just felt wrong and ended up with no solution.
I added the project to github so you guys can take a look at it as well:
https://github.com/Eidantz/Flutter_python_c
you can find weather.c and another .C file that I tried in /src folder.
the CMakeLists.txt is of course in /android/app folder
Thanks in advance guys!

swift-lldb compilation fails with c++11 error

I am trying to compile swift-lldb on Ubuntu 14.04 (following instructions from https://github.com/apple/swift-lldb). I have the following dependencies installed:
Clang-3.5
Cmake version 3.5.2
Python version 2.7.6
On running the build script step which is lldb/scripts/build-swift-cmake.py --test, I am seeing the following error:
CMake Warning at cmake/modules/HandleLLVMOptions.cmake:185 (message):
-fPIC is not supported.
Call Stack (most recent call first):
cmake/modules/HandleLLVMOptions.cmake:216 (add_flag_or_print_warning)
CMakeLists.txt:616 (include)
CMake Error at cmake/modules/HandleLLVMOptions.cmake:429 (message):
LLVM requires C++11 support but the '-std=c++11' flag isn't supported.
Call Stack (most recent call first):
CMakeLists.txt:616 (include)
I have defined environment variables CC and CXX to point to the clang C and C++ compilers.
root:/myswift# echo $CC
/usr/bin/clang
root:/myswift# echo $CXX
/usr/bin/clang++
I also found in the clang documentation that c++11 is supported by clang-3.5. Not sure what I am missing here. Can someone please help?
clang-4.0 mentioned as part of the installation should support the -std=c++11 flag (just tested clang-4.0.1). However, upgrading to clang-6.0 seems to solve this build process error.
Running cmake directly in the automatically created build directory (by the swift build scripts) could be used to investigate the build failure in more detail. To specify compilers here, rather than setting CC and CXX environment variables (which works well for GNU configure scripts), compilers can be set for cmake via
cmake -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ path_to_src_or_build_directory
An existing CMakeCache.txt might have to be removed, so that the above parameters are honored.
A problem with clang++ installations that I have observed is that clang++ cannot find C++ headers (i.e. if C++ headers are in non-standard locations other than /usr/include, unlikely in the case of Ubuntu though). In case /usr/bin/clang++ cannot compile a simple program like
#include <iostream>
using namespace std;
int main() {
cout << "hello" << endl;
return 0;
}
not being able to find the iostream include file, it might help to set --gcc-toolchain=/pathtoaworkinggcc, where pathtoaworkinggcc should include include, lib, bin, etc. of a working C++ compiler (possibly g++ in the case of a Ubuntu installation).

linker error - cross compile for Beaglebone Black on Debian (Jessie) using Eclipse 3.8.1

I am trying to get a basic cross compiler for the BeagleBone Black setup.
I tried to follow this tutorial but ran into some snags...
When dowloading the toolchain for the arm platform the tutorial showed the "gcc-arm-linux-gnueabi" as a package for Ubunto so I figutred there would be one for Debian... No dice, the closest I could find is the "arm-none-eabi" package. Being new to this I gave it a shot.
I made a simpe "Hello World" application as the tutorial suggested and it compiles under the standard tools. Under the cross tools however, I add the prefix amr-none-eabi- and the path /usr/bin/ the following is the result of the build.
make all
Building file: ../src/test.cpp
Invoking: Cross G++ Compiler
arm-none-eabi-g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP MF"src/test.d" -MT"src/test.d" -o "src/test.o" "../src/test.cpp"
Finished building: ../src/test.cpp
Building target: test
Invoking: Cross G++ Linker
arm-none-eabi-g++ -o "test" ./src/test.o
/usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function `exit':
/home/tin/projects/debian/arm-toolchain/collab-maint/newlib/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/exit.c:70: undefined reference to `_exit'
makefile:45: recipe for target 'test' failed
/usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/libc.a(lib_a-abort.o): In function `abort':
/home/tin/projects/debian/arm-toolchain/collab-maint/newlib/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/abort.c:63: undefined reference to `_exit'
/usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/libc.a(lib_a-fstatr.o): In function `_fstat_r':
/home/tin/projects/debian/arm-toolchain/collab-maint/newlib/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/fstatr.c:62: undefined reference to `_fstat'
/usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/libc.a(lib_a-openr.o): In function `_open_r':
/home/tin/projects/debian/arm-toolchain/collab-maint/newlib/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/openr.c:59: undefined reference to `_open'
/usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
/home/tin/projects/debian/arm-toolchain/collab-maint/newlib/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/sbrkr.c:58: undefined reference to `_sbrk'
/usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/libc.a(lib_a-signalr.o): In function `_kill_r':
/home/tin/projects/debian/arm-toolchain/collab-maint/newlib/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/signalr.c:61: undefined reference to `_kill'
/usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/libc.a(lib_a-signalr.o): In function `_getpid_r':
/home/tin/projects/debian/arm-toolchain/collab-maint/newlib/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/signalr.c:96: undefined reference to `_getpid'
/usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/libc.a(lib_a-writer.o): In function `_write_r':
/home/tin/projects/debian/arm-toolchain/collab-maint/newlib/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/writer.c:58: undefined reference to `_write'
/usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/libc.a(lib_a-closer.o): In function `_close_r':
/home/tin/projects/debian/arm-toolchain/collab-maint/newlib/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/closer.c:53: undefined reference to `_close'
/usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/libc.a(lib_a-isattyr.o): In function `_isatty_r':
/home/tin/projects/debian/arm-toolchain/collab-maint/newlib/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/isattyr.c:58: undefined reference to `_isatty'
/usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/libc.a(lib_a-lseekr.o): In function `_lseek_r':
/home/tin/projects/debian/arm-toolchain/collab-maint/newlib/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/lseekr.c:58: undefined reference to `_lseek'
/usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/libc.a(lib_a-readr.o): In function `_read_r':
/home/tin/projects/debian/arm-toolchain/collab-maint/newlib/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/readr.c:58: undefined reference to `_read'
collect2: error: ld returned 1 exit status
make: *** [test] Error 1
18:18:55 Build Finished (took 564ms)`
I can't seem to find anyhting that works to remove these errors. I would greatly appreciate any guidence I can get on this. I'm using Debian 8.1.0 and it is up to date.
I figured this out and my mistake was to use the wrong toolchain...
Linaro makes a toolchain for the hard float arm architecture.
Simply get the linked archive, extract it, and point eclipse in the right direction. I've now got eclipse to proerly build programs for the beaglebone. I've also got eclipse to properly connect to the remote application on the BBB.
Cheers,

Eclipse, Macos 10.8 and C++11

I'm trying to use C++11 but eclipse is having some trouble with it. I've used macports to get gcc48, and I've followed various guides for getting eclipse to use the new compiler, including this, this,
and I've also changed the compiler command from the eclipse standard to the g++-mp-4.8 as explained here
I am trying to build the following program:
#include <iostream>
#include<memory>
using namespace std;
int main() {
std::unique_ptr<double> ptr(new double);
*ptr = 11.345;
cout << (*ptr) << endl;
return 0;
}
The terminal will compile this fine,
make all
Building file: ../src/C++11.cpp
Invoking: Cross G++ Compiler
/opt/local/bin/g++ -I/opt/local/bin -I/opt/local/include -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"src/C++11.d" -MT"src/C++11.d" -o "src/C++11.o" "../src/C++11.cpp"
Finished building: ../src/C++11.cpp
Building target: C++11
Invoking: Cross G++ Linker
g++ -o "C++11" ./src/C++11.o
Finished building target: C++11
and the program runs just as expected. However, in eclipse, I still get the error message Symbol 'unique_ptr' could not be resolved.
I would like to continue using eclipse as more than just a project manager and makefile builder, so any help on this would be appreciated!
Rather than using g++, one can use clang++. I used the answers Error when compiling some simple c++ code, clang 3.1 can't see unique_ptr? and How to compile a C++0x code on Eclipse CDT on mac? as guides to come up with the following steps:
change the compiler in the Project->Properties->C/C++ Build -> Settings -> Gcc C++ Compiler -> Command (change g++ to clang++).
in Project->Properties->C/C++ Build -> Settings -> Gcc C++ Compiler -> Miscellaneous, append -std=c++11 -stdlib=libc++ to the flags.
do the same as one for the linker under C/C++ Build -> Settings -> Gcc C++ Linker -> Command
in Properties->C/C++ Build -> Settings -> Gcc C++ Linker -> Miscellaneous, add -stdlib=libc++ to the Linker flags.
in Properties->C/C++ General -> Preprocessor Include Paths, Macros,etc -> Providers -> CDT GCC Builtin Compiler Settings, turn off the Share option, and append -std=c++11 to the Command to get compiler specs.
The compilation works perfectly and the program runs well. That eclipse doesn't recognize the smart pointer appears to be a bug: see Turn off eclipse errors (that arent really errors)

Undefined reference to 'glib'

I would like to parse a config file using glib in Codeblocks which I use. So I want to do exactly the example which is described here first. I have a file named myconfig.cfg and and a code programming.c. I just copy and paste the code to see if glib works but unfortunately it does not work. I did the installation of glib2.0 using sudo apt-get, I found where are the libs in glibs using
pkg-config --cflags --libs glib-2.0
and in this path
project->Build Options->Compiler Settings-> Other Options
I added
-I/usr/include/glib-2.0 -I/usr/lib/arm-linuxgnuebihf/glib-2.0/include
When I build and run the programming.c I have these errors
-------------- Build: Debug in programming ---------------
gcc -Wall -g -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -std=c99 -c /home/pi/Desktop/programming/main.c -o obj/Debug/main.o
g++ -o bin/Debug/programming obj/Debug/main.o /usr/lib/libmysqlclient.so.16
obj/Debug/main.o: In function `main':
/home/pi/Desktop/programming/main.c:22: undefined reference to `g_key_file_new'
/home/pi/Desktop/programming/main.c:26: undefined reference to `g_key_file_load_from_file'
/home/pi/Desktop/programming/main.c:28: undefined reference to `g_log'
/home/pi/Desktop/programming/main.c:34: undefined reference to `g_slice_alloc'
/home/pi/Desktop/programming/main.c:37: undefined reference to `g_key_file_get_string'
/home/pi/Desktop/programming/main.c:39: undefined reference to `g_key_file_get_locale_string'
/home/pi/Desktop/programming/main.c:41: undefined reference to `g_key_file_get_boolean_list'
/home/pi/Desktop/programming/main.c:43: undefined reference to `g_key_file_get_integer_list'
/home/pi/Desktop/programming/main.c:45: undefined reference to `g_key_file_get_string_list'
/home/pi/Desktop/programming/main.c:47: undefined reference to `g_key_file_get_integer'
/home/pi/Desktop/programming/main.c:49: undefined reference to `g_key_file_get_double_list'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 6 seconds)
11 errors, 0 warnings
Am I missing something? I tried also to do in the same way with libconfig but again I have undefined reference. Is the problem the path?
UPDATE
With the usage of pkg-config --libs glib-2.0 it returns me -lglib-2.0
In Codeblocks I inserted it(lglib-2.0) in
project->Build Options->Linker Settings-> Link Libraries
and now I have this error:
**(process:3751): ERROR ** No such file or directory
Trace/breakpoint trap
You are not linking against the library, which is why you're getting linker errors ("undefined reference").
Check the output of pkg-config --libs glib-2.0, without --cflags, and make sure it's incorporated in your project settings somehow.