C++ template working fine for GCC but showing compile time error in LLVM-GCC compiler - iphone

typedef char TCHAR;
template <class T> class MyTemplateString
{
};
template <class T> class MyList
{
};
typedef MyTemplateString<TCHAR> MyString;
MyList<MyString> outlist;// here it's showing compile time error
The error is:
Implicit instantiation of undefined template MyList <MyTemplateString<char>>
Works fine with GCC compiler only but does not work in LLVM-GCC compiler.

The code as posted above compiles fine here without any errors or warnings using both g++ and llvm-g++:
$ g++ -Wall -c template.cpp
$ llvm-g++ -Wall -c template.cpp
Version info:
$ g++ -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5666.3~123/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)
$ llvm-g++ -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/llvmgcc42/llvmgcc42-2335.9~9/src/configure --disable-checking --enable-werror --prefix=/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --enable-llvm=/var/tmp/llvmgcc42/llvmgcc42-2335.9~9/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.9)
My guess is that your real problem lies elsewhere.

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).

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

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

Using clang++ for code analysis in an Autotools project in Eclipse

I am using Eclipse 4.2 on Mac OS 10.8, with the command line tools (Xcode 4.6.3) installed. The clang compiler supports C++11 by means of using the following flags: -std=c++11 -stdlib=libc++.
I have an Autotools-managed project in Eclipse. Real compilation works as expected after overriding CXX and CXXFLAFGS environment variables when configure is called. However, the static code analysis in Eclipse continues to use GCC (the version installed with Xcode is GCC 4.2), so there is no support for C++11, and lots of lines display errors that are not real ones, making static code analysis almost useless.
Using homebrew I also installed GCC 4.7, but I have not succeeded to make Eclipse use that version (or clang++) for performing static code analysis.
Is it possible, when using an Autotools-managed project, to make Eclipse use a different compiler for the static code analysis? Where should I specify that?
After installing Xcode 5, and following the directions in this question, I managed to solve the problem (I cannot test anymore whether this applies to Xcode 4.6 too).
The solution is to go to Project properties -> C/C++ General -> Preprocessor Include Paths, Macros etc. -> Providers -> CDT GCC Built-in Compiler Settings, and in Command to get compiler specs: append -std=c++11 -stdlib=libc++.
After doing that change, the line should look like:
${COMMAND} -E -P -v -dD ${INPUTS} -std=c++11 -stdlib=libc++

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)