Building a statically linked executable with Swift on Ubuntu - swift

I'm trying to build an statically linked executable from a swift source on Ubuntu.
Calling
swift build -Xswiftc -static-stdlib
as suggested in Compile Swift script with static Swift core library
returns this error:
/usr/bin/ld.gold: error: cannot find -lFoundation
Some educated guesses:
Researching this hasn't led me very far, I know it means the library can't be found. Maybe it isn't in the compiler's path ?
Full error message:
user#user-VirtualBox:/path/to/project$ swift build -Xswiftc -static-stdlib
Compile Swift Module 'projectName' (4 sources)
Linking ./.build/debug/projectName
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/usr/bin/ld.gold: error: cannot find -lFoundation
/path/to/project/Sources/SomeClass_1.swift:67: error: undefined reference to '_TMaC10Foundation17JSONSerialization'
/path/to/project/Sources/SomeClass_1.swift:67: error: undefined reference to '_TFVC10Foundation17JSONSerialization14WritingOptionsau13prettyPrintedS1_'
/path/to/project/Sources/SomeClass_1.swift:68: error: undefined reference to '_TMaC10Foundation8NSString'
/path/to/project/Sources/SomeClass_1.swift:68: error: undefined reference to '_TFVE10FoundationSS8Encodingau4utf8S0_'
/path/to/project/Sources/SomeClass_1.swift:68: error: undefined reference to '_TFC10Foundation8NSStringCfT4dataVS_4Data8encodingSu_GSqS0__'
/path/to/project/Sources/SomeClass_1.swift:69: error: undefined reference to '_TWPC10Foundation8NSObjects9EquatableS_'
/path/to/project/Sources/SomeClass_1.swift:72: error: undefined reference to '_TFC10Foundation8NSStringCfT13stringLiteralVs12StaticString_S0_'
/path/to/project/Sources/SomeClass_1.swift:76: error: undefined reference to '_TMaC10Foundation8NSString'
/path/to/project/Sources/SomeClass_1.swift:76: error: undefined reference to '_TFC10Foundation8NSStringCfT13stringLiteralVs12StaticString_S0_'
/path/to/project/Sources/SomeClass_2.swift:73: error: undefined reference to '_TMaC10Foundation17JSONSerialization'
/path/to/project/Sources/SomeClass_2.swift:73: error: undefined reference to '_TFVC10Foundation17JSONSerialization14WritingOptionsau13prettyPrintedS1_'
/path/to/project/Sources/SomeClass_2.swift:74: error: undefined reference to '_TMaC10Foundation8NSString'
/path/to/project/Sources/SomeClass_2.swift:74: error: undefined reference to '_TFVE10FoundationSS8Encodingau4utf8S0_'
/path/to/project/Sources/SomeClass_2.swift:74: error: undefined reference to '_TFC10Foundation8NSStringCfT4dataVS_4Data8encodingSu_GSqS0__'
/path/to/project/Sources/SomeClass_2.swift:75: error: undefined reference to '_TWPC10Foundation8NSObjects9EquatableS_'
/path/to/project/Sources/SomeClass_2.swift:78: error: undefined reference to '_TFC10Foundation8NSStringCfT13stringLiteralVs12StaticString_S0_'
/path/to/project/Sources/SomeClass_2.swift:82: error: undefined reference to '_TMaC10Foundation8NSString'
/path/to/project/Sources/SomeClass_2.swift:82: error: undefined reference to '_TFC10Foundation8NSStringCfT13stringLiteralVs12StaticString_S0_'
/path/to/project/Sources/SomeClass_3.swift:106: error: undefined reference to '_TMaC10Foundation17JSONSerialization'
/path/to/project/Sources/SomeClass_3.swift:106: error: undefined reference to '_TFVC10Foundation17JSONSerialization14WritingOptionsau13prettyPrintedS1_'
/path/to/project/Sources/SomeClass_3.swift:107: error: undefined reference to '_TFVE10FoundationSS8Encodingau4utf8S0_'
/path/to/project/Sources/SomeClass_3.swift:107: error: undefined reference to '_TFC10Foundation8NSStringCfT4dataVS_4Data8encodingSu_GSqS0__'
/path/to/project/Sources/SomeClass_3.swift:108: error: undefined reference to '_TWPC10Foundation8NSObjects9EquatableS_'
/path/to/project/Sources/main.swift:24: error: undefined reference to '_TMaC10Foundation12NSDictionary'
/path/to/project/Sources/main.swift:24: error: undefined reference to '_TFC10Foundation12NSDictionaryCft17dictionaryLiteralGSaTP_P____S0_'
/path/to/project/Sources/main.swift:51: error: undefined reference to '_TMaC10Foundation12NSDictionary'
/path/to/project/Sources/main.swift:51: error: undefined reference to '_TFC10Foundation12NSDictionaryCft17dictionaryLiteralGSaTP_P____S0_'
/path/to/project/Sources/main.swift:99: error: undefined reference to '_TMaC10Foundation12NSDictionary'
/path/to/project/Sources/main.swift:99: error: undefined reference to '_TFC10Foundation12NSDictionaryCft17dictionaryLiteralGSaTP_P____S0_'
/path/to/project/Sources/main.swift:112: error: undefined reference to '_TMaC10Foundation12NSDictionary'
/path/to/project/Sources/main.swift:112: error: undefined reference to '_TFC10Foundation12NSDictionaryCft17dictionaryLiteralGSaTP_P____S0_'
/path/to/project/Sources/main.swift:167: error: undefined reference to '_TMaC10Foundation17JSONSerialization'
/path/to/project/Sources/main.swift:167: error: undefined reference to '_TFVC10Foundation17JSONSerialization14WritingOptionsau13prettyPrintedS1_'
/path/to/project/Sources/main.swift:168: error: undefined reference to '_TFVE10FoundationSS8Encodingau4utf8S0_'
/path/to/project/Sources/main.swift:168: error: undefined reference to '_TFC10Foundation8NSStringCfT4dataVS_4Data8encodingSu_GSqS0__'
/path/to/project/Sources/main.swift:169: error: undefined reference to '_TWPC10Foundation8NSObjects9EquatableS_'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
error: exit(1): /path/to/swift-3.0.2-RELEASE-ubuntu16.04/usr/bin/swift-build-tool -f /path/to/project/.build/debug.yaml

The problem is that Foundation is not available as static library. There is an open bug for this:
https://bugs.swift.org/browse/SR-2205
You might be able to work around this problem if you could build a static Foundation lib, e.g. as part of building Swift from source.

Related

Protobuf for MATLAB fails to build in Cygwin

I am trying to build the protobuf compiler for MATLAB using github.com/BraunPhilipp/protobuf-matlab (forked from farsounders code). I followed the instructions at the site and I keep getting this error:
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: CMakeFiles/protoc.dir/home/kiran/protobuf/src/google/protobuf/compiler/main.cc.o:main.cc:(.text+0x2f3): undefined reference to farsounder::protobuf::compiler::matlab::MatlabGenerator::MatlabGenerator()' /usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: CMakeFiles/protoc.dir/home/kiran/protobuf/src/google/protobuf/compiler/main.cc.o:main.cc:(.text+0x3dc): undefined reference to farsounder::protobuf::compiler::matlab::MatlabGenerator::~MatlabGenerator()' /usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: CMakeFiles/protoc.dir/home/kiran/protobuf/src/google/protobuf/compiler/main.cc.o:main.cc:(.text+0x57e): undefined reference to `farsounder::protobuf::compiler::matlab::MatlabGenerator::~MatlabGenerator()' collect2: error: ld returned 1 exit status
Any help would be great

Getting "undefined symbol: Float8GetDatum" when creating function in PostgreSQL

I am using postgresql 11.5 in redhat linux 7.3.
In the sql script, the function is created as following:
create or replace function alpine_miner_float_array_sum_accum(state float[], ind float[])
returns float[]
AS 'alpine_miner', 'alpine_miner_float_array_sum_accum'
language C immutable;
But it gives the following error:
ERROR: could not load library "/usr/pgsql-11/lib/alpine_miner.so": /usr/pgsql-11/lib/alpine_miner.so: undefined symbol: Float8GetDatum
SQL state: XX000
I found that /usr/pgsql-11/lib/alpine_miner.so does exist and the output of ld command:
linux-vdso.so.1 => (0x00007ffda65d6000)
libc.so.6 => /lib64/libc.so.6 (0x00007eff25a67000)
/lib64/ld-linux-x86-64.so.2 (0x00007eff26051000)
ldd command:
ld: warning: cannot find entry symbol _start; not setting start address
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `construct_md_array'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `get_call_result_type'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `ArrayGetNItems'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `logf'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `deconstruct_array'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `CurrentMemoryContext'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `acosf'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `GetAttributeByName'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `elog_finish'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `errstart'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `pg_detoast_datum'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `exp'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `sqrtf'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `MemoryContextAllocZero'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `elog_start'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `errmsg'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `BlessTupleDesc'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `get_typlenbyvalalign'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `Float8GetDatum'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `log'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `pow'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `errdetail'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `DatumGetFloat8'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `errfinish'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `sqrt'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `heap_form_tuple'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `format_procedure'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `construct_array'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `MemoryContextAlloc'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `pfree'
/usr/pgsql-11/lib/alpine_miner.so: undefined reference to `errcode'
Any idea with that? Thanks in advance.
When you built alpine_miner.so, you built it against a PostgreSQL installation that was configured differently from the one where you are trying to use it.
In the case of the title problem, alpine_miner.so was built with USE_FLOAT8_BYVAL undefined, but your PostgreSQL has it defined:
#ifdef USE_FLOAT8_BYVAL
static inline Datum
Float8GetDatum(float8 X)
{
union
{
float8 value;
int64 retval;
} myunion;
myunion.value = X;
return Int64GetDatum(myunion.retval);
}
#else
extern Datum Float8GetDatum(float8 X);
#endif
But the list of undefined linker references also suggests that you are trying to load the shared object into a PostgreSQL that is either ancient or modified:
For example, BlessTupleDesc has been in the server since commit 375369acd1c in April 2004.
To get further help, you'll have to disclose the exact make and version of your PostgreSQL and the exact build process for alpine_miner.so.

Error while running make command for srilm

While executing make command, I recieve the following error:
/home/cse/phd/16071009/NLP//lib/i686-m64/libmisc.a(File.o): In function File::~File()':
/home/cse/phd/16071009/NLP/misc/src/File.cc:127: undefined reference tolibiconv_close'
/home/cse/phd/16071009/NLP//lib/i686-m64/libmisc.a(File.o): In function File::reopen(char const*, char const*)':
/home/cse/phd/16071009/NLP/misc/src/File.cc:167: undefined reference tolibiconv_close'
/home/cse/phd/16071009/NLP//lib/i686-m64/libmisc.a(File.o): In function File::reopen(char const*)':
/home/cse/phd/16071009/NLP/misc/src/File.cc:217: undefined reference tolibiconv_close'
/home/cse/phd/16071009/NLP//lib/i686-m64/libmisc.a(File.o): In function File::reopen(char const*, unsigned long, int)':
/home/cse/phd/16071009/NLP/misc/src/File.cc:249: undefined reference tolibiconv_close'
/home/cse/phd/16071009/NLP//lib/i686-m64/libmisc.a(File.o): In function File::reopen(std::string&, int)':
/home/cse/phd/16071009/NLP/misc/src/File.cc:273: undefined reference tolibiconv_close'
/home/cse/phd/16071009/NLP//lib/i686-m64/libmisc.a(File.o): In function File::fgetsUTF8(char*, int)':
/home/cse/phd/16071009/NLP/misc/src/File.cc:387: undefined reference tolibiconv'
/home/cse/phd/16071009/NLP/misc/src/File.cc:345: undefined reference to libiconv_open'
/home/cse/phd/16071009/NLP/misc/src/File.cc:349: undefined reference tolibiconv_open'
collect2: error: ld returned 1 exit status
test -f ../bin/i686-m64/ngram
make[2]: * [../bin/i686-m64/ngram] Error 1
make[2]: Leaving directory /home/cse/phd/16071009/NLP/lm/src'
make[1]: *** [release-programs] Error 1
make[1]: Leaving directory/home/cse/phd/16071009/NLP'
make: * [World] Error 2
[16071009#compute-01 NLP]$
The -liconv appears nowhere in the link command, so that's why you're
getting the undefined references. Try putting:
SYS_LIBRARIES = -L<path-to-libiconv_install> -liconv
For example, if you install srilm on Ubuntu x64, edit this file: common/Makefile.site.i686-m64. Make sure the -L option points to the directory that has the libiconv.so or libiconv.a file.
For me, libiconv install srilm on Ubuntu 18.04 x64 using make are locate on /usr/local/lib. So I add following line to common/Makefile.site.i686-m64:
SYS_LIBRARIES = -L/usr/local/lib -liconv
Solution from: http://mailman.speech.sri.com/pipermail/srilm-user/2014q3/001694.html

fortran: using pgplot with eclipse photran

So I am really not a Fortran programmer at all, but I have some code I am working with that uses the pgplot graphics libraries in fortran. I am able to get the code running in fortran from the console using the following commands.
gfortran -o simple discrete.f -lpgplot -IX11
discrete.f is the name of the file. So this works when I run it from the console. However, I want to run the code in the eclipse photran plugin so that I can use the debugger so that I can step through the code and observe some of the variables. I tried to put the -lpgplot and -IX11 flags in Eclipse, but I am getting errors about pgbbuf and pgnumb_ functions as undefined reference (which means that the -lpgplot function is not working when called from eclipse.
Can anyone please tell me how to set the flags correctly to run this code in Photran so that I can compile it and see the pgplot figure come up?
I am adding the console output:
02:57:05 **** Clean-only build of configuration Debug for project burglar_code_martin ****
make clean
rm -rf ./burglary_model.o burglar_code_martin
02:57:05 Build Finished (took 61ms)
02:57:05 **** Build of configuration Debug for project burglar_code_martin ****
make all
Building file: ../burglary_model.f
Invoking: GNU Fortran Compiler
gfortran -funderscoring -I/usr/lib -O0 -g -Wall -c -fmessage-length=0 -lpgplot -IX11 -o "burglary_model.o" "../burglary_model.f"
Warning: Nonconforming tab character in column 1 of line 225
Warning: Nonconforming tab character in column 1 of line 228
../burglary_model.f:155.27:
call probcheck(frac,1,outc)
1
Warning: Rank mismatch in argument 'problist' at (1) (rank-1 and scalar)
../burglary_model.f:54.33:
call probcheck(robprob,1,outcome)
1
Warning: Rank mismatch in argument 'problist' at (1) (rank-1 and scalar)
../burglary_model.f:95.30:
call probcheck(placeprob,1,outcome)
1
Warning: Rank mismatch in argument 'problist' at (1) (rank-1 and scalar)
../burglary_model.f:206.36:
subroutine output(A,burgsatloc,t,l,pic,screen,A0,Bbar)
1
Warning: Unused dummy argument 'burgsatloc' at (1)
../burglary_model.f:206.44:
subroutine output(A,burgsatloc,t,l,pic,screen,A0,Bbar)
1
Warning: Unused dummy argument 'pic' at (1)
../burglary_model.f:206.51:
subroutine output(A,burgsatloc,t,l,pic,screen,A0,Bbar)
1
Warning: Unused dummy argument 'screen' at (1)
../burglary_model.f:145.32:
integer l,pic,screen,i,j,k,PGOPEN,burgsatloc(512,*),nbar,outc
1
Warning: Unused variable 'k' declared at (1)
../burglary_model.f:146.15:
real rand,red,green,blue
1
Warning: Unused variable 'rand' declared at (1)
../burglary_model.f:143.53:
subroutine initialize(burgsatloc,B,l,pic,screen,rbar,Bbar)
1
Warning: Unused dummy argument 'screen' at (1)
../burglary_model.f:4.58:
integer i,j,n,l,pic,screen,guy,burgsatloc(512,512),k,
1
Warning: Unused variable 'k' declared at (1)
Finished building: ../burglary_model.f
Building target: burglar_code_martin
Invoking: GNU Fortran Linker
gfortran -lpgplot -IX11 -o "burglar_code_martin" ./burglary_model.o
./burglary_model.o: In function `output_':
/media/jaimini/workspace/eclipsejuno/burglar_code_martin/Debug/../burglary_model.f:241: undefined reference to `pgbbuf_'
/media/jaimini/workspace/eclipsejuno/burglar_code_martin/Debug/../burglary_model.f:242: undefined reference to `pgnumb_'
/media/jaimini/workspace/eclipsejuno/burglar_code_martin/Debug/../burglary_model.f:244: undefined reference to `pgenv_'
/media/jaimini/workspace/eclipsejuno/burglar_code_martin/Debug/../burglary_model.f:246: undefined reference to `pglab_'
/media/jaimini/workspace/eclipsejuno/burglar_code_martin/Debug/../burglary_model.f:247: undefined reference to `pgimag_'
/media/jaimini/workspace/eclipsejuno/burglar_code_martin/Debug/../burglary_model.f:253: undefined reference to `pgebuf_'
./burglary_model.o: In function `initialize_':
/media/jaimini/workspace/eclipsejuno/burglar_code_martin/Debug/../burglary_model.f:165: undefined reference to `pgopen_'
/media/jaimini/workspace/eclipsejuno/burglar_code_martin/Debug/../burglary_model.f:168: undefined reference to `pgpap_'
/media/jaimini/workspace/eclipsejuno/burglar_code_martin/Debug/../burglary_model.f:169: undefined reference to `pgask_'
/media/jaimini/workspace/eclipsejuno/burglar_code_martin/Debug/../burglary_model.f:170: undefined reference to `pgscir_'
/media/jaimini/workspace/eclipsejuno/burglar_code_martin/Debug/../burglary_model.f:175: undefined reference to `pgscr_'
/media/jaimini/workspace/eclipsejuno/burglar_code_martin/Debug/../burglary_model.f:181: undefined reference to `pgscr_'
/media/jaimini/workspace/eclipsejuno/burglar_code_martin/Debug/../burglary_model.f:187: undefined reference to `pgscr_'
/media/jaimini/workspace/eclipsejuno/burglar_code_martin/Debug/../burglary_model.f:193: undefined reference to `pgscr_'
/media/jaimini/workspace/eclipsejuno/burglar_code_martin/Debug/../burglary_model.f:199: undefined reference to `pgscr_'
./burglary_model.o: In function `implicit':
/media/jaimini/workspace/eclipsejuno/burglar_code_martin/Debug/../burglary_model.f:109: undefined reference to `pgclos_'
collect2: ld returned 1 exit status
make: *** [burglar_code_martin] Error 1
02:57:05 Build Finished (took 209ms)

how can I fix the error with making mtree

Hello I'm new to this and I don't understand, what's going on.
I need mtree for my iPhone and got an error.
And this is what I get:
In file included from compare.c:62:
vis.h:43: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘size_t’
In file included from compare.c:65:
extern.h:52: warning: redundant redeclaration of ‘compare’
extern.h:40: warning: previous declaration of ‘compare’ was here
extern.h:59: warning: redundant redeclaration of ‘getmode’
/usr/include/unistd.h:700: warning: previous declaration of ‘getmode’ was here
extern.h:60: warning: redundant redeclaration of ‘setmode’
/usr/include/unistd.h:736: warning: previous declaration of ‘setmode’ was here
compare.c: In function ‘compare’:
compare.c:186: error: ‘struct stat’ has no member named ‘st_mtim’
compare.c:187: error: ‘struct stat’ has no member named ‘st_mtim’
compare.c:192: error: ‘struct stat’ has no member named ‘st_mtim’
make[1]: *** [compare.o] Error 1
make: *** [all] Error 2
The full message is at http://pastebin.com/rVUfVP75
compare.c:186: error: ‘struct stat’ has no member named ‘st_mtim’
It should be st_mtime. It looks like a typo.
The structure definition is here:
http://pubs.opengroup.org/onlinepubs/007908799/xsh/sysstat.h.html