Compiling superopt on windows - makefile

I'm triing to compile the superoptimizer on windows. (https://github.com/bonzini/superopt)
Unfortunatly my knowledge of make is very limited. I tried:
make CPU=-D386 superopt
Which gives me the error:
cc superopt.c -o superopt
process_begin: CreateProcess(NULL, cc superopt.c -o superopt, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [superopt] Fehler 2
After setting the compiler to gcc manually with:
make CPU=-D386 superopt CC=gcc
I get the following error:
gcc superopt.c -o superopt
In file included from superopt.c:27:0:
superopt.h:104:2: error: #error You have to choose target CPU type (--with-arch).
#error You have to choose target CPU type (--with-arch).
^
In file included from superopt.h:130:0,
from superopt.c:27:
longlong.h:1465:14: error: unknown type name 'UQItype'
extern const UQItype __clz_tab[];
^
superopt.c:32:21: fatal error: version.h: No such file or directory
compilation terminated.
make: *** [superopt] Fehler 1
It seems it does't properly selects i386.
Any hints would be greatly appreciated.

That is not the source code of
GNU superopt. It is the source code of someone's project
to patch GNU superopt, last updated 2008, and seemingly
abandoned a hard-hat area.
This is the source code of
GNU superopt. Extract the tarball and build as you have attempted
with:
make CC=gcc CPU=-DI386 superopt
Note: I386, not 386.
You will see warnings like:
warning: incompatible implicit declaration of built-in function 'foo'
because the 20 yearold C code does not diligently include the standard
headers that prototype the standard functions that it calls, but superopt will build successfully.

Related

How to fix undefined reference LLVM error while linking CXX executable

I was trying to build a llvm-slicer from:
https://github.com/IAIK/ios-analysis-llvmslicer
and I follow the instructions:
cd llvm-slicer
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE="Release" -DLLVM_TARGETS_TO_BUILD="AArch64;X86" -DLLVM_ENABLE_EH=YES -DLLVM_ENABLE_RTTI=ON ..
make -j4 opt
make -j4 llvm-slicer
But when I execute the last command make -j4 llvm-slicer, I got an error:
[100%] Built target LLVMAnalysis
[100%] Linking CXX executable ../../bin/llvm-slicer
/usr/bin/ld: ../../lib/libLLVMSlicer.a(FunctionStaticSlicer.cpp.o): in function `llvm::Pass* llvm::callDefaultCtor<(anonymous namespace)::FunctionSlicer>()':
FunctionStaticSlicer.cpp:(.text._ZN4llvm15callDefaultCtorIN12_GLOBAL__N_114FunctionSlicerEEEPNS_4PassEv+0x1c): undefined reference to `vtable for (anonymous namespace)::FunctionSlicer'
collect2: error: ld returned 1 exit status
make[3]: *** [tools/llvm-slicer/CMakeFiles/llvm-slicer.dir/build.make:116: bin/llvm-slicer] Error 1
make[2]: *** [CMakeFiles/Makefile2:9647: tools/llvm-slicer/CMakeFiles/llvm-slicer.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:9654: tools/llvm-slicer/CMakeFiles/llvm-slicer.dir/rule] Error 2
make: *** [Makefile:2740: llvm-slicer] Error 2
I have no idea about how to fix it and I couldn't find any similar issues on Google, I hope someone can help me to figure it out, many thx.
There can be several scenarios for this issue, but in my opinion, here the scenario is for the given information that your default compiler (_ZN...something errors mostly because of compilers or linkers) is earlier version of gnu (gcc for c, g++ for c++) in your host pc (or maybe another compiler other than clang) and struggling about resolving a c++ feature anonymous namespace, as, a part of given error says:
/usr/bin/ld: ../../lib/libLLVMSlicer.a(FunctionStaticSlicer.cpp.o): in function `llvm::Pass* llvm::callDefaultCtor<(anonymous namespace)::FunctionSlicer>()':
FunctionStaticSlicer.cpp:(.text._ZN4llvm15callDefaultCtorIN12_GLOBAL__N_114FunctionSlicerEEEPNS_4PassEv+0x1c): undefined reference to `vtable for (anonymous namespace)::FunctionSlicer'
For this, there are several things you can do:
1-) You can change your compiler for building. In command window, you can export clang and clang++ as your compiler before cmake configuration. Here I assume that you installed new versions of clang compiler from anywhere, even github clone, I can give several examples here how to export and you can adapt one of them to your case easily:
export CC=clang
export CXX=clang++
another version:
export CC=clang-11
export CXX=clang++-11
another version:
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
another version:
export CC=/usr/bin/clang-12
export CXX=/usr/bin/clang++-12
another github clone version:
export CC=~/llvm/llvm-project/build/bin/clang
export CXX=~/llvm/llvm-project/build/bin/clang++
Even if this does not change your compiler, you can change your compiler while configuring with cmake by -DCMAKE_C_COMPILER={your-c-compiler} and -DCMAKE_CXX_COMPILER={your-c++-compiler} cmake flags. Try either with gcc or clang. Here is an example configuration in your case:
cmake \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_BUILD_TYPE="Release" \
-DLLVM_TARGETS_TO_BUILD="AArch64;X86" \
-DLLVM_ENABLE_EH=YES \
-DLLVM_ENABLE_RTTI=ON ..
2-) Error can be because of c++ standard, you can add -DCMAKE_CXX_STANDARD=14 (Default C++ standard using by LLVM) flag as cmake configuration like:
cmake -DCMAKE_BUILD_TYPE="Release" -DLLVM_TARGETS_TO_BUILD="AArch64;X86" -DLLVM_ENABLE_EH=YES -DLLVM_ENABLE_RTTI=ON -DCMAKE_CXX_STANDARD=14 ..
3-) Even if didn't work above cases, you can remove anonymous namespace from FunctionStaticSlicer.cpp file (given in the error message) and try to build again. You can find these lines like this:
// some code here and do not delete
namespace { // delete this line
// as you can see there is no name of namespace that's why called 'anonymous'
// if it was it would be like 'namespace nmspcName {'
// some code here and do not delete
} // and delete this line, too
// some code here and do not delete
But this is really bad practice, even if it can solve your problem, I do not recommend.
Also you can try to do similar changes in CMakeLists.txt file or adding other cmake configuration flags, however in my opinion, you could solve your problem easily by 1. option which is changing your default compiler.

"unknown conversion type character 'l' in format" warning. Specifically when using MinGW Makefiles generated by cmake for Assimp

I've been trying unsuccessfully for a week to get a build of Assimp that is linkable with a project I'm compiling with MinGW.
It seems that the makefiles that cmake generates to build Assimp 4.1.0 are flawed somehow because when I try to use them I get some warnings which ultimately lead to a failure when trying to link "libassimp.dll"
CMakeFiles\assimp.dir/objects.a(Exporter.cpp.obj):Exporter.cpp:(.text+0x1571): undefined reference to `Assimp::ExportScene3MF(char const*, Assimp::IOSystem*, aiScene const*, Assimp::ExportProperties const*)'
collect2.exe: error: ld returned 1 exit status
code\CMakeFiles\assimp.dir\build.make:3159: recipe for target 'code/libassimp.dll' failed
mingw32-make[2]: *** [code/libassimp.dll] Error 1
CMakeFiles\Makefile2:289: recipe for target 'code/CMakeFiles/assimp.dir/all' failed
mingw32-make[1]: *** [code/CMakeFiles/assimp.dir/all] Error 2
Makefile:131: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
Before it gets to this the only error it seems is a format error in certain header files which use the %llu conversion type when referencing the ai_snprintf function.
warning: unknown conversion type character 'l' in format [-Wformat=]
warning: too many arguments for format [-Wformat-extra-args]
I'm using the latest MinGW which has g++ version 6.3.0, by default using the c++14 standard. I did a test to see if this standard on windows didn't support %llu but when I wrote a CMakeLists.txt file, generated a makefile, and compiled using the makefile, it gave no errors and ran as expected.
I've tried using cmake to generate a Visual Studio 2017 project and building it there and it links fine when used in Visual Studio. If I call the same functions and compile with MinGW it doesn't link, I guess this is just an interoperability problem, but it suggests I have everything assimp needs to be built properly.
My thoughts are, somehow assimp's cmake modules are defining what standard assimp should be compiled with, and that standard doesn't support %llu, but that sounds silly. I don't like to assume something is a bug but these warnings don't seem like they're thrown because I forgot to do something.
I've tried editing the makefile it gives me and adding to the front:
CXX = g++
CXXFLAGS = -Wall -std=c++11 $(DEBUG)
Cause somewhere it said that could work, but it didn't change anything.
I also tried defining the macro __USE_MINGW_ANSI_STDIO 1 for cmake but that didn't do anything either.
But I really don't know much about building binaries (though I've learned more than I expected to recently), so any advice, information, guidance is appreciated.

wxFreeChart and -mthreads

I’m trying to develop some plotting apps for Windows platform. I’m using Debian and built wxWidgets for cross-compiling as described here.
With MinGW compiler it works perfect and I have no problem with creating Win32 apps under Linux. But I faced some troubles with wxFreeChart.
I run ./configure --host=i386-mingw32 --with-wx-config=/usr/local/i586-mingw32/bin/wx-config
Then I run 'make' and getting error about
unrecognized command line option ‘-mthreads
Full output here:
~/dev/freechart/bk-deps g++ -c -o wxfreechart_lib_legend.o -I./include -I/usr/local/i586-mingw32/lib/wx/include/i586-mingw32msvc-msw-unicode-static-3.0 -I/usr/local/i586-mingw32/include/wx-3.0 -D_LARGEFILE_SOURCE=unknown -D__WXMSW__ -mthreads -O2 ./src/legend.cpp
g++: error: unrecognized command line option ‘-mthreads’
make: *** [wxfreechart_lib_legend.o] Error 1
The only advice I've seen was to remove '-mthreads' from code, but I have no idea where is it(
Problem described above is solved, but still no luck with building wxFreeChart.
Next errors I get were about some additional libs, which I finally solved by
CPPFLAGS="-I/usr/i586-mingw32msvc/include -I~/dev/wxWidgets-3.0.2/include" ./configure --host=i386-mingw32 --with-wx-config=/usr/local/i586-mingw32/bin/wx-config
I'm not sure that including .h from source folder ~/dev/wxWidgets is a good idea, but at least it solved some problems.
Now make crashing with messages like:
In file included from /usr/local/i586-mingw32/include/wx-3.0/wx/wx.h:17:0,
from ./include/wx/wxfreechartdefs.h:20,
from ./include/wx/legend.h:13,
from ./src/legend.cpp:10:
/usr/local/i586-mingw32/include/wx-3.0/wx/list.h: In constructor ‘wxListKey::wxListKey(const wxString&)’:
/usr/local/i586-mingw32/include/wx-3.0/wx/list.h:381:40: error: invalid use of incomplete type ‘class wxString’
or
/usr/local/i586-mingw32/include/wx-3.0/wx/containr.h:247:13: error: incomplete type ‘wxNavigationEnabled<wxControl>::BaseWindowClass {aka wxControl}’ used in nested name specifier
make: *** [wxfreechart_lib_legend.o] Error 1

error compiling uClibc (__NR_or1k_atomic undeclared)

I am following http://openrisc.net/toolchain-build.html to build gcc toolchain for openrisc or32.
I'm doing 'building by hand' flow and had passed
binutils
stage 1 gcc
install linux headers
and was to do 'compile uClibc' which is composed of commands below.
$ git clone git://openrisc.net/jonas/uClibc
$ cd uClibc
$ make ARCH=or32 defconfig
$ make PREFIX=${SYSROOT}
$ make PREFIX=${SYSROOT} install <br>
when I run 'make ARCH=or32 defconfig', I get this error.
CC libpthread/linuxthreads.old/attr.o
In file included from libpthread/linuxthreads.old/internals.h:30:0,
from libpthread/linuxthreads.old/attr.c:26:
./libpthread/linuxthreads.old/sysdeps/or32/pt-machine.h: In function 'testandset':
./libpthread/linuxthreads.old/sysdeps/or32/pt-machine.h:41:8: error: '__NR_or1k_atomic' undeclared (first use in this function)
./libpthread/linuxthreads.old/sysdeps/or32/pt-machine.h:41:8: note: each undeclared identifier is reported only once for each function it appears in
In file included from libpthread/linuxthreads.old/../linuxthreads.old_db/proc_service.h:20:0,
from libpthread/linuxthreads.old/../linuxthreads.old_db/thread_dbP.h:9,
from libpthread/linuxthreads.old/internals.h:32,
from libpthread/linuxthreads.old/attr.c:26:
./include/sys/procfs.h: At top level:
./include/sys/procfs.h:32:21: fatal error: asm/elf.h: No such file or directory
compilation terminated.
make: *** [libpthread/linuxthreads.old/attr.o] Error 1
Has anybody had same problem? I use CentOS 6.4.
gcc searches for the header file from the system in the order
/usr/local/include
libdir/gcc/target/version/include (libdir was /usr/lib in my case)
/usr/target/include
/usr/include
my system had sys/syscall.h under /usr/include so that file was used when sys/syscall under uClib/include should have been used. So I added -nostdinc so that gcc doesn't search the standard include path. Now it became
make PREFIX=${SYSROOT} -nostdinc
and it works!
The following command was also modified
make PREFIX=${SYSROOT} -nostdinc install
Cheers!

CMake/GCC "unrecognized option" on Mac OS X

I'm trying to create a project as a shared library in OS X using CMake 2.8 and gcc 4.6 (from macports). When CMake gets to the point of linking my library into a .dylib, I get the following error from gcc:
g++ -dynamiclib -headerpad_max_install_names -o libmycoollibrary.dylib etc...
g++: error: unrecognized option '-h'
make[2]: *** [libnrtCore.dylib] Error 1
make[1]: *** [CMakeFiles/nrtCore.dir/all] Error 2
make: *** [all] Error 2
This -headerpad_max_install_names seems to be the problem, but I've never seen it before. Does anyone know how to either get CMake to not include this option, or to get GCC to accept this option?
You can re-build cmake to fix this -- it's apparently generating code for the XCode / Darwin version of g++ (a special version of 4.2), which accepts a number of non-standard linker flags.
Just change the Modules/Platform/Darwin*.cmake files and re-build. The culprit lines look like this:
SET(CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first -headerpad_max_install_names")

Resources