I want to build a glib static library. I have installed MSYS2 and I have installed MinGW-W64 Win32 threads on to it. I didn't download the MSYS2 package. Instead, I've downloaded MinGW-W64 from SourceForge and installed it to the MSYS2 directory. That's how I have set up my system. I'm interested in compiling static libraries of GTK+ 3.24 for which I need GLib installed. How do I get about building a static library with the following setup? I'm not familiar with the Meson build system which is being used to compile GLib. I also don't know how to pass the install prefix and to build a static library. The command
meson builddir
gives the following output:
The Meson build system
Version: 0.49.0
Source dir: /home/Sean/glib-2.59.1
Build dir: /home/Sean/glib-2.59.1/builddir
Build type: native build
Project name: glib
Project version: 2.59.1
Native C compiler: gcc (gcc 8.1.0 "gcc.exe (i686-win32-dwarf-rev0, Built by MinGW-W64 project) 8.1.0")
Native C++ compiler: c++ (gcc 8.1.0 "c++.exe (i686-win32-dwarf-rev0, Built by MinGW-W64 project) 8.1.0")
Build machine cpu family: x86
Build machine cpu: x86
Compiler for C supports arguments -fno-strict-aliasing: YES
Checking if "GNU C visibility attributes test" compiles: NO
Compiler for C supports arguments -fvisibility=hidden: YES
Has header "alloca.h" : NO
Has header "crt_externs.h" : NO
Has header "dirent.h" : YES
Has header "float.h" : YES
Has header "fstab.h" : NO
Has header "grp.h" : NO
Has header "inttypes.h" : YES
Has header "limits.h" : YES
Has header "linux/magic.h" : NO
Has header "locale.h" : YES
Has header "mach/mach_time.h" : NO
Has header "memory.h" : YES
Has header "mntent.h" : NO
Has header "poll.h" : NO
Has header "pwd.h" : NO
Has header "sched.h" : YES
Has header "spawn.h" : NO
Has header "stdint.h" : YES
Has header "stdlib.h" : YES
Has header "string.h" : YES
Has header "strings.h" : YES
Has header "sys/auxv.h" : NO
Has header "sys/event.h" : NO
Has header "sys/filio.h" : NO
Has header "sys/inotify.h" : NO
Has header "sys/mkdev.h" : NO
Has header "sys/mntctl.h" : NO
Has header "sys/mnttab.h" : NO
Has header "sys/mount.h" : NO
Has header "sys/param.h" : YES
Has header "sys/resource.h" : NO
Has header "sys/select.h" : NO
Has header "sys/statfs.h" : NO
Has header "sys/stat.h" : YES
Has header "sys/statvfs.h" : NO
Has header "sys/sysctl.h" : NO
Has header "sys/time.h" : YES
Has header "sys/times.h" : NO
Has header "sys/types.h" : YES
Has header "sys/uio.h" : NO
Has header "sys/vfs.h" : NO
Has header "sys/vfstab.h" : NO
Has header "sys/vmount.h" : NO
Has header "sys/wait.h" : NO
Has header "termios.h" : NO
Has header "unistd.h" : YES
Has header "values.h" : NO
Has header "xlocale.h" : NO
Checking if "malloc.h" compiles: YES
Has header "linux/netlink.h" : NO
Header <locale.h> has symbol "LC_MESSAGES" : NO
Checking whether type "struct stat" has member "st_mtimensec" : NO
Checking whether type "struct stat" has member "st_mtim.tv_nsec" : NO
Checking whether type "struct stat" has member "st_atimensec" : NO
Checking whether type "struct stat" has member "st_atim.tv_nsec" : NO
Checking whether type "struct stat" has member "st_ctimensec" : NO
Checking whether type "struct stat" has member "st_ctim.tv_nsec" : NO
Checking whether type "struct stat" has member "st_birthtime" : NO
Checking whether type "struct stat" has member "st_birthtimensec" : NO
Checking whether type "struct stat" has member "st_birthtim" : NO
Checking whether type "struct stat" has member "st_birthtim.tv_nsec" : NO
Checking whether type "struct stat" has member "st_blksize" : NO
Checking whether type "struct stat" has member "st_blocks" : NO
Checking whether type "struct statfs" has member "f_fstypename" : NO
Checking whether type "struct statfs" has member "f_bavail" : NO
Checking whether type "struct dirent" has member "d_type" : NO
Checking whether type "struct statvfs" has member "f_basetype" : NO
Checking whether type "struct statvfs" has member "f_fstypename" : NO
Checking whether type "struct tm" has member "tm_gmtoff" : NO
Checking whether type "struct tm" has member "__tm_gmtoff" : NO
Compiler for C supports arguments -Wall: YES
Compiler for C supports arguments -Wduplicated-branches: YES
Compiler for C supports arguments -Wimplicit-fallthrough: YES
Compiler for C supports arguments -Wmisleading-indentation: YES
Compiler for C supports arguments -Wstrict-prototypes: YES
Compiler for C supports arguments -Wunused: YES
Compiler for C supports arguments -Wno-bad-function-cast -Wbad-function-cast: YES
Compiler for C supports arguments -Wno-pedantic -Wpedantic: YES
Compiler for C supports arguments -Werror=declaration-after-statement: YES
Compiler for C supports arguments -Werror=format=2: YES
Compiler for C supports arguments -Werror=implicit-function-declaration: YES
Compiler for C supports arguments -Werror=init-self: YES
Compiler for C supports arguments -Werror=missing-include-dirs: YES
Compiler for C supports arguments -Werror=missing-prototypes: YES
Compiler for C supports arguments -Werror=pointer-arith: YES
Compiler for C supports link arguments -Wl,-z,nodelete: NO
Compiler for C supports link arguments -Wl,-Bsymbolic-functions: YES
Checking for function "endmntent" : NO
Checking for function "endservent" : NO
Checking for function "fallocate" : NO
Checking for function "fchmod" : NO
Checking for function "fchown" : NO
Checking for function "fdwalk" : NO
Checking for function "fsync" : NO
Checking for function "getauxval" : NO
Checking for function "getc_unlocked" : NO
Checking for function "getfsstat" : NO
Checking for function "getgrgid_r" : NO
Checking for function "getmntent_r" : NO
Checking for function "getpwuid_r" : NO
Checking for function "getresuid" : NO
Checking for function "getvfsstat" : NO
Checking for function "gmtime_r" : NO
Checking for function "hasmntopt" : NO
Checking for function "inotify_init1" : NO
Checking for function "issetugid" : NO
Checking for function "kevent" : NO
Checking for function "kqueue" : NO
Checking for function "lchmod" : NO
Checking for function "lchown" : NO
Checking for function "link" : NO
Checking for function "localtime_r" : NO
Checking for function "lstat" : NO
Checking for function "mbrtowc" : YES
Checking for function "memalign" : NO
Checking for function "mmap" : NO
Checking for function "newlocale" : NO
Checking for function "pipe2" : NO
Checking for function "poll" : NO
Checking for function "prlimit" : NO
Checking for function "readlink" : NO
Checking for function "recvmmsg" : NO
Checking for function "sendmmsg" : NO
Checking for function "setenv" : NO
Checking for function "setmntent" : NO
Checking for function "strerror_r" : NO
Checking for function "strnlen" : YES
Checking for function "strsignal" : NO
Checking for function "strtod_l" : NO
Checking for function "strtoll_l" : NO
Checking for function "strtoull_l" : NO
Checking for function "symlink" : NO
Checking for function "timegm" : NO
Checking for function "unsetenv" : NO
Checking for function "uselocale" : NO
Checking for function "utimes" : NO
Checking for function "valloc" : NO
Checking for function "vasprintf" : YES
Checking for function "vsnprintf" : YES
Checking for function "wcrtomb" : YES
Checking for function "wcslen" : YES
Checking for function "wcsnlen" : YES
Checking for function "sysctlbyname" : NO
Checking for function "_NSGetEnviron" : NO
Checking for function "if_indextoname" : NO
Checking for function "if_nametoindex" : NO
Checking for function "splice" : NO
Checking for function "stpcpy" : NO
Checking for function "posix_memalign" : NO
Checking for function "posix_spawn" : NO
Checking for function "snprintf" : YES
Checking for function "strcasecmp" : YES
Checking for function "strncasecmp" : YES
Header <sys/sysmacros.h> has symbol "major" : NO
Header <sys/mkdev.h> has symbol "major" : NO
Header <sys/types.h> has symbol "major" : NO
Header <dlfcn.h> has symbol "RTLD_LAZY" : NO
Header <dlfcn.h> has symbol "RTLD_NOW" : NO
Header <dlfcn.h> has symbol "RTLD_GLOBAL" : NO
Message: Checking whether to use statfs or statvfs .. neither
Checking if "futex(2) system call" links: NO
Checking if "eventfd(2) system call" links: NO
Checking if "clock_gettime" links: NO
Checking if "clock_gettime in librt" links: NO
Checking if "open() option O_DIRECTORY" compiles: NO
Checking if "C99 vsnprintf" runs: NO (1)
Checking if "C99 snprintf" runs: NO (1)
Checking if "Unix98 printf positional parameters" runs: NO (1)
Checking if "nl_langinfo and CODESET" links: NO
Checking if "nl_langinfo (PM_STR)" links: NO
Checking if "nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)" links: NO
Checking if "nl_langinfo (ALTMON_n)" links: NO
Checking if "nl_langinfo (_NL_ALTMON_n)" links: NO
Checking if "signed" compiles: YES
Header <stddef.h> has symbol "ptrdiff_t" : YES
Checking if "sig_atomic_t" links: YES
Checking if "long long" compiles: YES
Checking if "long double" compiles: YES
Header <stddef.h> has symbol "wchar_t" : YES
Header <wchar.h> has symbol "wint_t" : YES
Checking if "uintmax_t in inttypes.h" compiles: YES
Checking if "uintmax_t in stdint.h" compiles: YES
Checking for size of "char" : 1
Checking for size of "short" : 2
Checking for size of "int" : 4
Checking for size of "void*" : 4
Checking for size of "long" : 4
Checking for size of "long long" : 8
Checking for size of "size_t" : 4
Checking for size of "ssize_t" : 4
Checking for alignment of "char" : 1
Checking for alignment of "short" : 2
Checking for alignment of "int" : 4
Checking for alignment of "void*" : 4
Checking for alignment of "long" : 4
Checking for alignment of "long long" : 8
Checking for alignment of "size_t" : 4
Checking if "__va_copy check" compiles: YES
Checking if "va_copy check" compiles: YES
Checking if "va_lists can be copied as values" runs: YES
Checking if "ISO C99 varargs macros in C" compiles: YES
Checking if "ISO C99 varargs macros in C++" compiles: YES
Checking if "GNUC varargs macros" compiles: YES
Has header "alloca.h" : NO
Has header "sys/poll.h" : NO
Has header "sys/types.h" : YES
Has header "winsock2.h" : YES
meson.build:1476:2: ERROR: Entry _WIN32_WINNT not in configuration data.
I'm not sure how to tell it to set an install prefix or even enable static build.
Thanks
You should be able to build glib with -Ddefault_library=static and you have to use a cross-file for mingw but you will fail to build the entire GTK stack statically as most of the libraries do not support it. So I personally just suggest living with shared libraries, there are no downsides really and everything will be supported that way.
Related
I'm trying to compile a Fortran program that uses the PLASMA libraries. Compilation fails with undefined reference to `__plasma_MOD_plasma_init'. Inside plasma.h (which i assume plasma.mod is the interface for), plasma_init is defined with one argument whereas it is called with two in the Fortran program. When removing the second argument though, i get Error: Missing actual argument for argument ‘info’ at (1). I haven't been able to make sense of this, so hopefully someone here can.
I'm using PLASMA 2.8.0 and gcc 6.3.0 20170516.
Here's the makefile. I tried including the pkgconfig which contains plasma.pc because i thought the function's implementation was missing.
#LIB_ROOT = path to the lib
INCLUDE_PLASMA := $(LIB_ROOT)/plasma_2.8.0/include
LIB_PLASMA := $(LIB_ROOT)/plasma_2.8.0/lib/pkgconfig
example: example.f90
gfortran -o example example.f90 -I$(INCLUDE_PLASMA) -L$(LIB_PLASMA)
Here's the minimal Fortran code :
program example
use plasma
implicit none
integer :: a = 1
integer :: info = 1
call plasma_init(a, info)
end program
In plasma.h, plasma_init is defined as:
int PLASMA_Init(int cores);
I solved my issue by correctly linking to the required libraries, here's the new makefile:
PLASMA_BUILD = [some directories]/plasma-installer_2.8.0/build
LIB_PLASMA := $(PLASMA_BUILD)/plasma_2.8.0/lib # contains libplasma.a, libcoreblas.a and libcoreblasqw.a
LIB_QUARK := $(PLASMA_BUILD)/plasma_2.8.0/quark # contains libquark.a
LIB_LAPACK := $(PLASMA_BUILD)/lapack-3.6.0 # contains liblapack.a and liblapacke.a
PLASMA_INTERFACE = $(PLASMA_BUILD)/plasma_2.8.0/control # contains plasma.mod
example: example.f90
gfortran -o example example.f90 -lpthread \
-L$(LIB_PLASMA) -lplasma -lcoreblas -lcoreblasqw \
-L$(LIB_QUARK) -lquark \
-L$(LIB_LAPACK) -llapacke -llapack \
-I$(PLASMA_INTERFACE)
I'm porting some code from C11 to C++. The project compiles fine in gcc and g++ but clang refuses to compile it. The offending lines are shown below:
static atomic_int sem = {0};
src/testdir.c:27:25: error: illegal initializer type 'atomic_int'
(aka '_Atomic(int)')
and
struct container {
volatile atomic_ullong workerThreadCount;
struct cfgoptions *config;
repaircmd_t *cmd;
};
Container container = {{0}, s, NULL};
src/testdir.c:334:25: error: illegal initializer type 'volatile atomic_ullong'
(aka 'volatile _Atomic(unsigned long long)')
Clang:
clang version 3.7.0 (tags/RELEASE_370/final)
gcc:
gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6)
Operating system:
Fedora 23
Test code:
https://gist.github.com/clockley/eb42964003a2e4fe6de97d5b192d61d3
P.S i = {0} or i(0) are the only valid initializers in C++ as atomic ints are not primitive types of the two only the former is valid C.
I believe this is a bug in clang.
Here's a simple test case, with the result of compiling it with gcc and clang:
$ cat c.c
static _Atomic int x = ( 42 );
static _Atomic int y = { 42 };
$ gcc-6.1.0 -std=c11 -c c.c
$ clang-3.7 -std=c11 -c c.c
c.c:2:24: error: illegal initializer type '_Atomic(int)'
static _Atomic int y = { 42 };
^
1 error generated.
$
C explicitly permits the initializer for a scalar object to be enclosed in braces (N1570 6.7.9p11). I see nothing that forbids such an initializer for an atomic object.
Atomics are an optional feature in C11, but both gcc and clang support it (neither predefines __STDC_NO_ATOMICS__).
As a workaround, I suggest just dropping the braces. This:
static _Atomic int z = 42;
is valid and accepted by both compilers.
If you're need the code to compile both as C and as C++, then you might want to reconsider that requirement. But if it's really necessary, you can use the __cplusplus predefined macro to distinguish between C and C++ compilers:
static _Atomic int foo =
#ifdef __cplusplus
{ 42 };
#else
42;
#endif
or play some other tricks with macros.
(I'll note that C11's <stdatomic.h> header defines a macro ATOMIC_VAR_INIT that's intended to be used to initialize atomic objects, with an example:
atomic_int guide = ATOMIC_VAR_INIT(42);
It appears to be needed for atomic objects with automatic storage duration, which doesn't apply here.)
I must disagree strongly with Mad Physicist. The braces {} are used to initialize an aggregate. A single int is not an aggregate. You may put the initializer in () if you like, but {} are verboten. It would be an aggregate if you dimensioned it out to one entry, as in:
static atomic_int sem[ 1 ] = { 0 };
or even
static atomic_int sem[] = { 0 };
if you're too lazy to count one integer initializer!
The gcc linker has a directive called NOLOAD that allows a section to be linked but not loaded in the final output. This directive is placed in the linker scatter file (see the example below). Is there an equivalent linker directive for IAR Workbench? I'm currently using IAR Embedded Workbench for ARM V7.20.2.
MEMORY
{
rom (rx) : ORIGIN = 0x00000000, LENGTH = 0x00010000
ram (rwx) : ORIGIN = 0x10000000, LENGTH = 0x00008000
}
SECTIONS
{
.my_section (NOLOAD):
{
*my_funcs.o(.text*)
} > rom
The following code compiles into an executable with no problems:
static const char *foo = "bar";
void main(void)
{
__asm__ ("mov %0,%%rax"
:
: "i"(&foo)
: "%rax");
}
But as a shared lib, I get an error:
static const char *foo = "bar";
void zot(void)
{
__asm__ ("mov %0,%%rax"
:
: "i"(&foo)
: "%rax");
}
Compilation result:
hacker#lab$ gcc -shared -o mini-lib mini-lib.c
/usr/bin/ld: /tmp/ccwume3d.o: relocation R_X86_64_32S against `.data'
can not be used when making a shared object; recompile with -fPIC
/tmp/ccwume3d.o: error adding symbols: Bad value
Compiling with -fPIC makes no difference. How can I tweak this in such a way that the linker will relocate a reference to the address of foo? It needs to be an immediate integer operand in the asm.
Update: I ended up using a different instruction that takes a memory operand, since there is apparently no way to do this with immediate operands.
Would be good if you could clarify what exactly you're trying to achieve.
There is no 64bit movq $imm64, %reg, so you'd have to use movabs instead.
But there's also the X and P operand modifiers which might help by ditching the PLT reference / PC-relative addresses; you could write:
static void *foo;
[ ... ]
void *out[2];
asm("lea %P2, %0\n\t"
"movabs %X2, %1\n\t" : "=r"(out[0]), "=a"(out[1]) : "g"(foo));
So the question is, do you know (or want to explicitly specify) the exact address of foo ?
If so, this must be done via the linker (mapfiles or command line options to the linker, not the compiler).
Otherwise ... movabs, lea and/or the usage of P / X might do what you're looking for.
I am attempting to install the sinatra-contrib gem on Windows 7, and I am getting the error shown below. Any ideas?
U:\>gem install sinatra-contrib
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing sinatra-contrib:
ERROR: Failed to build gem native extension.
C:/Ruby200-x64/bin/ruby.exe extconf.rb
checking for main() in -lssl... no
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... yes
checking for inotify_init() in sys/inotify.h... no
checking for __NR_inotify_init in sys/syscall.h... no
checking for writev() in sys/uio.h... no
checking for rb_wait_for_single_fd()... yes
checking for rb_enable_interrupt()... no
checking for rb_time_new()... yes
checking for windows.h... yes
checking for winsock.h... yes
checking for main() in -lkernel32... yes
checking for main() in -lrpcrt4... yes
checking for main() in -lgdi32... yes
creating Makefile
make
generating rubyeventmachine-x64-mingw32.def
compiling binder.cpp
cc1plus.exe: warning: command line option '-Wdeclaration-after-statement' is valid for C/ObjC but not for C++ [enabled by defa
cc1plus.exe: warning: command line option '-Wimplicit-function-declaration' is valid for C/ObjC but not for C++ [enabled by de
In file included from binder.cpp:20:0:
project.h:26:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
In file included from project.h:149:0,
from binder.cpp:20:
binder.h:35:34: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
In file included from c:\rubydevkit\mingw\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/include/proce
from c:/Ruby200-x64/include/ruby-2.0.0/ruby/win32.h:60,
from c:/Ruby200-x64/include/ruby-2.0.0/ruby/defines.h:153,
from c:/Ruby200-x64/include/ruby-2.0.0/ruby/ruby.h:70,
from c:/Ruby200-x64/include/ruby-2.0.0/ruby.h:33,
from em.h:24,
from project.h:150,
from binder.cpp:20:
c:\rubydevkit\mingw\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/include/sys/types.h:68:16: error: c
id_t pid_t'
In file included from binder.cpp:20:0:
project.h:97:13: error: 'pid_t' has a previous declaration as 'typedef int pid_t'
In file included from project.h:150:0,
from binder.cpp:20:
em.h:84:47: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
em.h:85:76: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
em.h:86:56: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
em.h:88:57: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
em.h:89:60: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
em.h:90:58: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
em.h:91:36: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
em.h:93:47: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
em.h:99:42: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
em.h:116:45: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
em.h:125:36: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
In file included from project.h:151:0,
from binder.cpp:20:
ed.h: In member function 'void EventableDescriptor::SetSocketInvalid()':
ed.h:43:40: warning: overflow in implicit constant conversion [-Woverflow]
In file included from project.h:154:0,
from binder.cpp:20:
eventmachine.h: At global scope:
eventmachine.h:46:61: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
eventmachine.h:47:112: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
eventmachine.h:48:69: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
eventmachine.h:50:73: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
eventmachine.h:65:75: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
eventmachine.h:66:74: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
eventmachine.h:67:77: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
eventmachine.h:68:41: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
In file included from project.h:154:0,
from binder.cpp:20:
eventmachine.h:103:58: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
eventmachine.h:105:60: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
eventmachine.h:108:41: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
make: *** [binder.o] Error 1
Gem files will remain installed in C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.1 for inspection.
Results logged to C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.1/ext/gem_make.out
sinatra-contrib depends on EventMachine, which is currently broken for Ruby 2.0 and even more, GCC 4.7.2 used by RubyInstaller.
There is a thread at RubyInstaller group about this here and was reported to EventMachine too, as issue #412
A request to separate sinatra-contrib from eventmachine was made too, long ago, as issue #30, but it never got fixed officially.
Until compilation issues with GCC 4.7.2 are solved in EventMachine, the only workaround will be ask sinatra maintainers to remove eventmachine dependency.
Hope that helps.