Undefined symbols for architecture x86_64 - in libboost_thread-mt.a - x86-64

boost::atomics::detail::lockpool::get_lock_for(void const volatile*)", referenced from:
boost::thread_detail::enter_once_region(boost::once_flag&) in libboost_thread-mt.a(once.o)
boost::thread_detail::commit_once_region(boost::once_flag&) in libboost_thread-mt.a(once.o)
boost::thread_detail::rollback_once_region(boost::once_flag&) in libboost_thread-mt.a(once.o)
ld: symbol(s) not found for architecture x86_64
I am running OS X Version 10.9.
Installed boost using the following option:
sudo port install boost +universal
$ ar -tv libboost_thread-mt.a
rw-r--r-- 502/501 21776 Dec 1 22:44 2013 __.SYMDEF
rw-r--r-- 502/80 925520 Dec 1 22:44 2013 thread.o
rw-r--r-- 502/80 18248 Dec 1 22:44 2013 once.o
rw-r--r-- 502/80 51216 Dec 1 22:44 2013 future.o
$ nm -a once.o
0000000000003168 s EH_frame0
0000000000003080 s GCC_except_table0
00000000000030cc s GCC_except_table1
0000000000003118 s GCC_except_table2
U __Unwind_Resume
0000000000000000 T __ZN5boost13thread_detail17enter_once_regionERNS_9once_flagE
0000000000003188 S __ZN5boost13thread_detail17enter_once_regionERNS_9once_flagE.eh
0000000000000130 T __ZN5boost13thread_detail18commit_once_regionERNS_9once_flagE
00000000000031c0 S __ZN5boost13thread_detail18commit_once_regionERNS_9once_flagE.eh
00000000000001a0 T __ZN5boost13thread_detail20rollback_once_regionERNS_9once_flagE
00000000000031f0 S __ZN5boost13thread_detail20rollback_once_regionERNS_9once_flagE.eh
0000000000003010 d __ZN5boost13thread_detailL10once_mutexE
0000000000003050 d __ZN5boost13thread_detailL7once_cvE
U __ZN5boost7atomics6detail8lockpool12get_lock_forEPVKv
U __ZSt9terminatev
U ___gxx_personality_v0
U _pthread_cond_broadcast
U _pthread_cond_wait
U _pthread_mutex_lock
U _pthread_mutex_unlock
One can notice the line "U __ZN5boost7atomics6detail8lockpool12get_lock_forEPVKv"
indicating get_lock_for is not defined. This is causing the issue.
How to get rid of this error. Any suggestion?

Link with more libraries. :)
-lboost_atomic for the get_lock_for in particular.

Related

Cocoapods pod repo push git

I am trying to push my pod to local repo. Before that, I have verified pod lib lint on my repo, and working fine locally
$ pod lib lint --swift-version=5.0 --allow-warnings
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /usr/local/sbin in PATH, mode 040777
-> SFLocationManager (1.0)
- WARN | source: Git SSH URLs will NOT work for people behind firewalls configured to only allow HTTP, therefore HTTPS is preferred.
- NOTE | xcodebuild: note: Using new build system
- NOTE | xcodebuild: note: Planning build
- NOTE | xcodebuild: note: Constructing build description
SFLocationManager passed validation.
After this, I have created tags and pushed to server
$ git tag
0.1.0
0.1.1
1.0
Then I have tried to test pod repo push command for local repo, which got failed
$ pod repo push git#git.url.com:ankit.thakur/locationmanager.git SFLocationManager.podspec --allow-warnings --swift-version=5.0 --local-only
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /usr/local/sbin in PATH, mode 040777
Validating spec
-> SFLocationManager (1.0)
- WARN | source: Git SSH URLs will NOT work for people behind firewalls configured to only allow HTTP, therefore HTTPS is preferred.
- ERROR | file patterns: The `source_files` pattern did not match any file.
- NOTE | xcodebuild: note: Using new build system
- NOTE | xcodebuild: note: Planning build
- NOTE | xcodebuild: note: Constructing build description
[!] The `SFLocationManager.podspec` specification does not validate.
Then I removed --local-only flag and ran again, but still failed.
$ pod repo push git#git.url.com:ankit.thakur/locationmanager.git SFLocationManager.podspec --allow-warnings --swift-version=5.0
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /usr/local/sbin in PATH, mode 040777
Validating spec
-> SFLocationManager (1.0)
- WARN | source: Git SSH URLs will NOT work for people behind firewalls configured to only allow HTTP, therefore HTTPS is preferred.
- ERROR | file patterns: The `source_files` pattern did not match any file.
- NOTE | xcodebuild: note: Using new build system
- NOTE | xcodebuild: note: Planning build
- NOTE | xcodebuild: note: Constructing build description
[!] The `SFLocationManager.podspec` specification does not validate.
Here is the pod version
$ pod --version
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /usr/local/sbin in PATH, mode 040777
1.6.0
Here is the podspec file:
#
# Be sure to run `pod lib lint SFLocationManager.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |spec|
spec.name = 'SFLocationManager'
spec.version = '1.0'
spec.summary = 'SFLocationManager is location based library for iOS and Mac'
# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
spec.description = <<-DESC
Location library in beta test version to fetch location with scheduled interval.
DESC
spec.homepage = 'https://git.url.com/ankit.thakur/locationmanager'
# spec.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
spec.license = { :type => 'MIT', :file => 'LICENSE' }
spec.author = { 'ankitthakur' => 'ankit.thakur#url.com' }
spec.source = { :git => 'git#git.url.com:ankit.thakur/locationmanager.git', :tag => spec.version.to_s }
# spec.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
spec.requires_arc = true
spec.ios.deployment_target = '10.0'
spec.osx.deployment_target = '10.10'
spec.source_files = 'SFLocationManager/Sources/Common/**/*.swift'
# spec.ios.source_files = 'SFLocationManager/Sources/iOS/**/*.swift'
# spec.osx.source_files = 'SFLocationManager/Sources/OSX/**/*.swift'
# spec.resource_bundles = {
# 'SFLocationManager' => ['SFLocationManager/Assets/*.png']
# }
spec.frameworks = 'CoreLocation'
# spec.public_header_files = 'Pod/Classes/**/*.h'
# spec.frameworks = 'UIKit', 'MapKit'
# spec.dependency 'AFNetworking', '~> 2.3'
end
The response of spec.source_files is
$ ls -al SFLocationManager/Sources/Common/**/*.swift
-rw-r--r--# 1 ankitthakur staff 2710 Apr 25 18:02 SFLocationManager/Sources/Common/GeocoderUtils/Geocoder.swift
-rw-r--r--# 1 ankitthakur staff 613 Apr 25 18:21 SFLocationManager/Sources/Common/LocationManager/LocationConfiguration.swift
-rw-r--r--# 1 ankitthakur staff 324 Apr 25 18:02 SFLocationManager/Sources/Common/LocationManager/LocationError.swift
-rw-r--r--# 1 ankitthakur staff 241 Apr 25 18:02 SFLocationManager/Sources/Common/LocationManager/LocationEventType.swift
-rw-r--r--# 1 ankitthakur staff 7144 Apr 25 18:36 SFLocationManager/Sources/Common/LocationManager/LocationManager.swift
-rw-r--r--# 1 ankitthakur staff 4649 Apr 25 18:02 SFLocationManager/Sources/Common/Model/Location.swift
-rw-r--r--# 1 ankitthakur staff 3939 Apr 25 18:27 SFLocationManager/Sources/Common/Trigger/LocationTriggerManager.swift
As per suggestions in provided solutions, my updated Podspec is
#
# Be sure to run `pod lib lint SFLocationManager.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |spec|
spec.name = 'SFLocationManager'
spec.version = '1.0'
spec.summary = 'SFLocationManager is location based library for iOS and Mac'
# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
spec.description = <<-DESC
Location library in beta test version to fetch location with scheduled interval.
DESC
spec.homepage = 'https://git.promobitech.com/ankit.thakur/locationmanager'
# spec.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
spec.license = { :type => 'MIT', :file => 'LICENSE' }
spec.author = { 'ankitthakur' => 'ankit.thakur#promobitech.com' }
spec.source = { :git => 'git#git.promobitech.com:ankit.thakur/locationmanager.git', :tag => spec.version.to_s }
# spec.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
spec.requires_arc = true
spec.ios.deployment_target = '10.0'
spec.osx.deployment_target = '10.10'
spec.source_files = 'SFLocationManager/Sources/Common/GeocoderUtils/*.{swift}',
'SFLocationManager/Sources/Common/LocationManager/*.{swift}',
'SFLocationManager/Sources/Common/Model/*.{swift}',
'SFLocationManager/Sources/Common/Trigger/*.{swift}'
# spec.ios.source_files = 'SFLocationManager/Sources/iOS/**/*.{swift}'
# spec.osx.source_files = 'SFLocationManager/Sources/OSX/**/*.{swift}'
# spec.resource_bundles = {
# 'SFLocationManager' => ['SFLocationManager/Assets/*.png']
# }
spec.frameworks = 'CoreLocation'
# spec.public_header_files = 'Pod/Classes/**/*.h'
# spec.frameworks = 'UIKit', 'MapKit'
# spec.dependency 'AFNetworking', '~> 2.3'
end
but it is still not working.
Here is the my podspec file:
Admin:locationmanager ankitthakur$ ls -al
total 40
drwxr-xr-x 10 ankitthakur staff 320 Apr 25 20:38 .
drwxr-xr-x 9 ankitthakur staff 288 Apr 25 20:38 ..
-rw-r--r-- 1 ankitthakur staff 6148 Apr 25 20:38 .DS_Store
drwxr-xr-x 14 ankitthakur staff 448 Apr 26 14:50 .git
drwxr-xr-x 10 ankitthakur staff 320 Apr 25 20:38 Example
-rw-r--r-- 1 ankitthakur staff 1086 Apr 25 20:38 LICENSE
-rw-r--r-- 1 ankitthakur staff 1029 Apr 25 20:38 README.md
drwxr-xr-x 4 ankitthakur staff 128 Apr 25 20:51 SFLocationManager
-rw-r--r-- 1 ankitthakur staff 2241 Apr 26 14:49 SFLocationManager.podspec
lrwxr-xr-x 1 ankitthakur staff 27 Apr 25 20:38 _Pods.xcodeproj -> Example/Pods/Pods.xcodeproj
The error says:
file patterns: The `source_files` pattern did not match any file.
This means that you have written a wrong pattern.
So you should correct your source_files like the following
s.source_files = "FOLDERNAME/*.{swift}"
(This will include all the Swift files under the folder "FOLDERNAME")
In case you have multiple folders, do like the following:
s.source_files = "FOLDERNAME1/*.{swift}" , "FOLDERNAME2/*.{swift}"

How to query changes to IDB predicates?

I want to make changes to some EDBs and then find out how the IDBs changed as a result.
The docs say that the query stage comes after the final stage and "has access to the effects of stage FINAL". But if I run
query '_(id) <- ^level(id; _).'
(where level is an IDB) I get
block block_1Z7PZ61E: line 2: error: predicate level is an IDB, therefore deltas for it will not be available until stage final. (code: STAGE_INITIAL_IDB_DELTA)
^level(id; _).
^^^^^^^^^^^^^
1 ERROR
BloxCompiler reported 1 error in block 'block_1Z7PZ61E'
I also tried following the diff predicate example. But this
query '_(id) <- (level\level#prev)(id; _).'
causes a syntax error:
block block_1Z80EFSZ: line 2: error: illegal character 'U+005C' (code: ILLEGAL_CHARACTER)
(level\level#prev)(id; _).
^
block block_1Z80EFSZ: line 2: error: unexpected token 'level' (code: UNEXPECTED_TOKEN)
(level\level#prev)(id; _).
^^^^^
block block_1Z80EFSZ: line 2: error: unexpected token ')' (code: UNEXPECTED_TOKEN)
(level\level#prev)(id; _).
^
block block_1Z80EFSZ: line 2: error: unexpected token ';' (code: UNEXPECTED_TOKEN)
(level\level#prev)(id; _).
^
4 ERRORS
BloxCompiler reported 4 errors in block 'block_1Z80EFSZ'
Unfortunately the diff predicate functionality is not yet released (as of Dec 2016). We've noted that as a documentation bug to fix. The feature is expected in LB 4.4 in Q1 2017.
Here's a simple example for printing or querying the values in the IDB predicate after changes to the EDB. You don't need to use delta logic in this case.
[dan#glycerine Fri Dec 30 09:55:54 ~/Temp]
$ cat foo.logic
foo(x), foo_id(x: y) -> int(y).
edb[x] = y -> foo(x), int(y).
idb[x] = y -> foo(x), int(y).
idb[x] = y <- edb[x] + 10 = y.
[dan#glycerine Fri Dec 30 09:56:33 ~/Temp]
$ lb create --overwrite foo && lb addblock foo --name foo --file foo.logic && lb exec foo '+foo(x), +foo_id[x] = 1, +edb[x] = 5.'
created workspace 'foo'
added block 'foo'
[dan#glycerine Fri Dec 30 09:57:23 ~/Temp]
$ lb print foo edb
[10000000005] 1 5
[dan#glycerine Fri Dec 30 09:57:28 ~/Temp]
$ lb print foo idb
[10000000005] 1 15
[dan#glycerine Fri Dec 30 09:57:32 ~/Temp]
$ lb exec foo '^edb[x] = 15 <- foo_id[x] = 1.'
[dan#glycerine Fri Dec 30 09:57:54 ~/Temp]
$ lb print foo idb
[10000000005] 1 25
[dan#glycerine Fri Dec 30 09:57:55 ~/Temp]
$ lb query foo '_[x] = edb[x].'
/--------------- _ ---------------\
[10000000005] 1 15
\--------------- _ ---------------/
I can think of a couple options for watching changes more as they happen. In once case you could create a watcher predicate and add values to it like this.
watcher(x, y) -> int(x), int(y).
^watcher(x, y) <- foo_id[x] = id, ^idb[id] = y.
That could be enhanced to have its own entity and timestamp...
Another way, if you are using web services to make the EDB updates, is to use
lb web-server monitor -w foo idb
to watch a list of predicates.

Increasing max size of Mongo BSON Objects results in Boost library compile error

I need to increase the max size of BSON objects in Mongo. Since the BSON object size is not directly configurable, I've attempted to do this by changing the constant in the source and recompiling.
The problem is that any attempt to change const int BSONObjMaxUserSize = 16 * 1024 * 1024; to anything other than 16 in this file causes a crash when the boost library goes to compile.
Leaving BSONObjMaxUserSize as 16 compiles perfectly, but changing it to anything else fails. I've tried numerous options (8,32, even 7 for good measure.)
I'm experiencing this in version 2.6.6 stable.
In file included from src/third_party/boost/boost/type_traits/type_with_alignment.hpp:19:0,
from src/third_party/boost/boost/smart_ptr/make_shared.hpp:17,
from src/third_party/boost/boost/make_shared.hpp:15,
from src/third_party/boost/boost/smart_ptr.hpp:28,
from src/mongo/pch.h:50,
from src/mongo/db/dur_commitjob.cpp:31:
src/third_party/boost/boost/static_assert.hpp:124:85: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>'
sizeof(::boost::STATIC_ASSERTION_FAILURE< BOOST_STATIC_ASSERT_BOOL_CAST( B ) >)>\
^
src/mongo/db/dur_commitjob.cpp:147:9: note: in expansion of macro 'BOOST_STATIC_ASSERT'
BOOST_STATIC_ASSERT( sizeof(void*)==4 || UncommittedBytesLimit > BSONObjMaxInternalSize * 6 );
^
src/third_party/boost/boost/static_assert.hpp:124:86: error: template argument 1 is invalid
sizeof(::boost::STATIC_ASSERTION_FAILURE< BOOST_STATIC_ASSERT_BOOL_CAST( B ) >)>\
^
src/mongo/db/dur_commitjob.cpp:147:9: note: in expansion of macro 'BOOST_STATIC_ASSERT'
BOOST_STATIC_ASSERT( sizeof(void*)==4 || UncommittedBytesLimit > BSONObjMaxInternalSize * 6 );
^
src/mongo/db/dur_commitjob.cpp:147:102: error: invalid type in declaration before ';' token
BOOST_STATIC_ASSERT( sizeof(void*)==4 || UncommittedBytesLimit > BSONObjMaxInternalSize * 6 );
^
In file included from src/third_party/boost/boost/filesystem/v3/path_traits.hpp:23:0,
from src/third_party/boost/boost/filesystem/v3/path.hpp:25,
from src/third_party/boost/boost/filesystem/path.hpp:31,
from src/mongo/util/paths.h:21,
from src/mongo/db/storage/durable_mapped_file.h:35,
from src/mongo/db/dur.h:34,
from src/mongo/db/dur_commitjob.h:34,
from src/mongo/db/dur_commitjob.cpp:33:
src/third_party/boost/boost/system/error_code.hpp:214:36: error: 'boost::system::posix_category' defined but not used [-Werror=unused-variable]
static const error_category & posix_category = generic_category();
^
src/third_party/boost/boost/system/error_code.hpp:215:36: error: 'boost::system::errno_ecat' defined but not used [-Werror=unused-variable]
static const error_category & errno_ecat = generic_category();
^
src/third_party/boost/boost/system/error_code.hpp:216:36: error: 'boost::system::native_ecat' defined but not used [-Werror=unused-variable]
static const error_category & native_ecat = system_category();
^
cc1plus: all warnings being treated as errors
scons: *** [build/linux2/normal/mongo/db/dur_commitjob.o] Error 1
scons: building terminated because of errors.
It's not been a problem here:
cloned 0ae940b456ceafc3a0d47 from github
changed builder.h:
diff --git a/src/mongo/bson/util/builder.h b/src/mongo/bson/util/builder.h
index ae31074..8e34aee 100644
--- a/src/mongo/bson/util/builder.h
+++ b/src/mongo/bson/util/builder.h
## -63,7 +63,7 ## namespace mongo {
update $push (append) operation
various db.eval() type operations
*/
- const int BSONObjMaxUserSize = 16 * 1024 * 1024;
+ const int BSONObjMaxUserSize = 24 * 1024 * 1024;
/*
Sometimes we need objects slightly larger - an object in the replication local.oplog
Compiles cleanly with scons -j 8. Here's my system information:
OS version
/tmp/mongo$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.1 LTS
Release: 14.04
Codename: trusty
kernel version
/tmp/mongo$ uname -a
Linux desktop 3.13.0-37-generic #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
gcc version
/tmp/mongo$ gcc -v
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.2-19ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
boost version
/tmp/mongo$ dpkg --status libboost-all-dev
Package: libboost-all-dev
Status: install ok installed
Priority: optional
Section: libdevel
Installed-Size: 26
Maintainer: Ubuntu Developers <ubuntu-devel-discuss#lists.ubuntu.com>
Architecture: amd64
Source: boost-defaults
Version: 1.54.0.1ubuntu1

Systemtap %M printf format only returns one character

I'm trying to print the data received on a socket - the contents of ubuf on the return of sys_recv. I cant get the %M format specifier to work properly. Can someone please explain how to use it properly. Thanks
stap -L 'kernel.function("sys_recv#net/socket.c")'
kernel.function("sys_recv#net/socket.c:1800") $fd:int $ubuf:void* $size:size_t $flags:unsigned int
using this probe:
[laris#kakitis stap]$ cat socket-recv.stp
#! /usr/bin/env stap
probe kernel.function("sys_recv#net/socket.c").return {
if (pid() == target())
printf ("%s fd %d size %d ubuf %p %10M \n ", ppfunc(),$fd,$size,$ubuf,$ubuf)
}
From my reading of the man page the format %10M should return 10 bytes from the location pointed to by $ubuf:void but I only get 1. Adjusting the parameter 10 shifts the one character output rather than showing more or less memory
[root#kakitis stap]# stap -x 16796 socket-recv.stp
sys_recv fd 13 size 64071 ubuf 0x86ceca0 70
sys_recv fd 13 size 62679 ubuf 0x86cf210 50
Changing 10 to 2 gives this
[root#kakitis stap]# stap -x 16796 socket-recv.stp
sys_recv fd 13 size 64071 ubuf 0x86ceca0 70
sys_recv fd 13 size 62679 ubuf 0x86cf210 50
System particulars are:
[laris#kakitis stap]$ stap --version
Systemtap translator/driver (version 2.1/0.154, rpm 2.1-2.fc17)
Copyright (C) 2005-2013 Red Hat, Inc. and others
This is free software; see the source for copying conditions.
enabled features: AVAHI LIBRPM LIBSQLITE3 NSS TR1_UNORDERED_MAP NLS
[laris#kakitis stap]$ uname -a
Linux kakitis 3.4.33 #1 SMP Tue Jan 7 14:15:58 EST 2014 i686 i686 i386 GNU/Linux
[laris#kakitis stap]$ cat /etc/redhat-release
Fedora release 17 (Beefy Miracle)
Don't confuse the output-width and precision parameters for printf(). The following will do what you meant:
printf ("%33.10M", $pointer)
to print 10 bytes (20 hex characters) in a 33-character-wide output field. One or both numbers can be replaced by *, so that the respective widths are passed as parameters before the $pointer. The upstream man page has been updated with an example.

How do I set the timezone for Perl's localtime()?

In Perl, I'd like to look up the localtime in a specific timezone. I had been using this technique:
$ENV{TZ} = 'America/Los_Angeles';
my $now = scalar localtime;
print "It is now $now\n";
# WORKS: prints the current time in LA
However, this is not reliable -- notably, if I prepend another localtime() call before setting $ENV{TZ}, it breaks:
localtime();
$ENV{TZ} = 'America/Los_Angeles';
my $now = scalar localtime;
print "It is now $now\n";
# FAILS: prints the current time for here instead of LA
Is there a better way to do this?
Use POSIX::tzset.
use POSIX qw(tzset);
my $was = localtime;
print "It was $was\n";
$ENV{TZ} = 'America/Los_Angeles';
$was = localtime;
print "It is still $was\n";
tzset;
my $now = localtime;
print "It is now $now\n";
$ perl -v
This is perl, v5.8.8 built for x86_64-linux-thread-multi
Copyright 1987-2006, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
$ perl tzset-test.pl
It was Wed Apr 15 15:58:10 2009
It is still Wed Apr 15 15:58:10 2009
It is now Wed Apr 15 12:58:10 2009
I'd strongly suggest using a module to do this. Specifically, I'd suggest using DateTime (see Perl DateTime Wiki or CPAN
Then you should be able to do something like the following:
use strict;
use warnings;
use DateTime;
my $dt = DateTime->now(); # *your* local time assuming your system knows it!
my $clone1 = $dt->clone; # taking a copy.
$clone1->set_time_zone('America/Los_Angeles');
print "$clone1\n"; # output using ISO 8601 format (there a lot of choices)
print "$dt\n";
Whilst your code works fine for me on both Linux (Perl 5.10.0) and MacOS X (5.8.9), there is a possible solution.
The underlying C functons used by Perl (ctime(), localtime(), etc) call tzset() the first time they're invoked, but not necessarily afterwards. By calling it yourself you should ensure that the timezone structures are correctly re-initialised after any change to $TZ.
Fortunately this is easy - the tzset() function is available in the POSIX module:
#!/usr/bin/perl -w
use POSIX qw[tzset];
$ENV{'TZ'} = 'Europe/London';
tzset();
print scalar localtime();
NB: some Google searches suggest that this is only necessary with Perl versions up to and including 5.8.8. Later versions always call tzset() automatically before each call to localtime().
use Time::Zone;
my $TZ = 'America/Los_Angeles';
my $now = scalar localtime time() + tz_offset($TZ);
print "It is now $now\n";
seems to work here. (The 'scalar' is redundant here since $now gives it scalar context, but it's also nice to be explicit.)
As per the comment, I got the original problem. This seems to fix it for me, but given that others aren't having the original problem, the "seems to work here" bit is intended as an invitation for those people to try this solution as well to ensure it doesn't break anything. (I have to wonder if alnitak noticed the difference between what I posted and the original post?)
Expanding on BrianP007 answer you use both TZ and _tzset
$was = localtime;
print "It was $was\n";
$ENV{TZ} = 'CST6CDT'; # America/Chicago
Time::Piece::_tzset(); # Local time is now Chicago Time
$was = localtime;
print "It is $was\n"; # Right now in Chicago
The trick is the TZ is set from your location to GMT. So normally you would think Chicago is UTC-6, but from Chicago it is 6 hours to UTC which = 'CST6'.
See http://science.ksc.nasa.gov/software/winvn/userguide/3_1_4.htm
Executive Summary:
Setting $ENV{TZ}='/*&+000000000005' and calling Time::Piece::_tzset() fixes localtime() to agree with the windoz system clock.
Sanguinarily gory details:
On Strawberry Perl, windoz 7/64, none of the "Standard" time zones works in the TZ environmental variable to localize localtime(). 'America/Chicago' gives exactly the same time as 'America/Los_Angeles' == 'CDT' == 'CST' == 'UTC' == '-01:00', etc. The list is infinite.
Every timezone on http://www.timeanddate.com/time/zones/ that I tried gives the right time if you are in Greenwich.
Every time from: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
also fails to change localtime() at all. And, there is no apparent indication. They do nothing and say nothing.
There is NO tzset() on windoz:
POSIX::tzset not implemented on this architecture
There is not even any concept of POSIX ???
C:\bin>cpan install POSIX
...
Warning: Cannot install POSIX, don't know what it is.
Try the command i /POSIX/
It appears to be baked into win8 and there are some dot NOT libraries for it.
For Austin, Texas, in the very Center of Central Intergalactic Time, thee correct $ENV{TZ} which gives me a scalar localtime() which ~agrees with the o/s level time function and the windoz clock is:
'/*&+5' !!! Yes Slash-Star-Ampersand-Plus-5 works!
P:\br1\sxsw.2015\sx-2015.0318\done>time
The current time is: 16:36:39.44
...
Time=Apr 14 16:36:42 2015, ENV->TZ=/*&+5
By running a for loop and trying random values from various posts, for Strawberry Perl uname='Win32 strawberry-perl 5.18.2.2...' with known timezone bugs, any 3 chars I tried (didn't try + or -) followed by +/- and a small number worked. Here is an array of text values and their output below:
use Time::Piece;
#tz = ('', 'CDT+5', 'CST+5', 'FKU+5', 'XYZ+5', '+5', '+05', '+05.00',
'America/Chicago', 'America/Los_Angeles', 'CDT',
'CST', 'UTC', 'PDT', 'PST', '-01:00', '+01:00', '-05:00'.
'ACDT', 'EASST', '5000', '+0500', '+5:00', '+05:00', 'SSS+1', 'SSS+0',
'zzz-1', 'ZZ1+5', '123+5', '___+5', '/*&+5', , '/*&+05', '/*&+005',
'/*&+000000000005');
foreach $tz (#tz) {
$ENV{TZ} = $tz if $tz;
Time::Piece::_tzset() if $tz;
printf("T%s, ENV->TZ=%s\n", scalar localtime, $ENV{TZ} || 'NoTZ');
}
Most every try with anything but XXX . +|- . integer gave UTC, but many were an hour off for no reason (America/Los_Angeles and America/Chicago gave the same value). I am almost sure I used to get away with just CDT and CST, possibly on Activestate (switched to Strawberry to compile my own Perl modules rather than rely on Activestate for everything). This is the first major snarl.
I rebuilt DateTime from scratch and it worked fine. DateTime::TimeZone::Local::Win32 "failed for 'Win32::TieRegistry'"
Here's the sorted result of the attempted zones above:
P:\br1\sxsw.2015\sx-2015.0318\done>bb | sort
Running c:/bin/bb.pl Tue Apr 14 21:43:56 2015
TTue Apr 14 16:43:56 2015, ENV->TZ=/*&+000000000005
TTue Apr 14 16:43:56 2015, ENV->TZ=/*&+005
TTue Apr 14 16:43:56 2015, ENV->TZ=/*&+05
TTue Apr 14 16:43:56 2015, ENV->TZ=/*&+5
TTue Apr 14 16:43:56 2015, ENV->TZ=___+5
TTue Apr 14 16:43:56 2015, ENV->TZ=123+5
TTue Apr 14 16:43:56 2015, ENV->TZ=CDT+5
TTue Apr 14 16:43:56 2015, ENV->TZ=CST+5
TTue Apr 14 16:43:56 2015, ENV->TZ=FKU+5
TTue Apr 14 16:43:56 2015, ENV->TZ=XYZ+5
TTue Apr 14 16:43:56 2015, ENV->TZ=ZZ1+5
ABOVE ALL WORKED Below most failed with UTC or +1 hour???
TTue Apr 14 20:43:56 2015, ENV->TZ=SSS+1
TTue Apr 14 21:43:56 2015, ENV->TZ=-01:00
TTue Apr 14 21:43:56 2015, ENV->TZ=+01:00
TTue Apr 14 21:43:56 2015, ENV->TZ=+05
TTue Apr 14 21:43:56 2015, ENV->TZ=+05:00
TTue Apr 14 21:43:56 2015, ENV->TZ=+0500
TTue Apr 14 21:43:56 2015, ENV->TZ=+5
TTue Apr 14 21:43:56 2015, ENV->TZ=+5:00
TTue Apr 14 21:43:56 2015, ENV->TZ=5000
TTue Apr 14 21:43:56 2015, ENV->TZ=CDT
TTue Apr 14 21:43:56 2015, ENV->TZ=CDT
TTue Apr 14 21:43:56 2015, ENV->TZ=CST
TTue Apr 14 21:43:56 2015, ENV->TZ=PDT
TTue Apr 14 21:43:56 2015, ENV->TZ=PST
TTue Apr 14 21:43:56 2015, ENV->TZ=SSS+0
TTue Apr 14 21:43:56 2015, ENV->TZ=UTC
TTue Apr 14 22:43:56 2015, ENV->TZ=-05:00ACDT
TTue Apr 14 22:43:56 2015, ENV->TZ=+05.00
TTue Apr 14 22:43:56 2015, ENV->TZ=America/Chicago
TTue Apr 14 22:43:56 2015, ENV->TZ=America/Los_Angeles
TTue Apr 14 22:43:56 2015, ENV->TZ=EASST
TTue Apr 14 22:43:56 2015, ENV->TZ=zzz-1
Even after finding and installing the Holy Grail, the TzFile module for the Olsen Database, it is still screwed, no difference!
Installing C:\bin\strawberry_perl_5_18\perl\site\lib\DateTime\TimeZone\Tzfile.pm
ZEFRAM/DateTime-TimeZone-Tzfile-0.010.tar.gz
C:\bin\strawberry_perl_5_18\perl\bin\perl.exe ./Build install --uninst 1 -- OK
Here are all of the alleged timezones which do nothing on this platform from:
#atz = DateTime::TimeZone->all_names();
printf("All tz names [%d] = %s\n", scalar #atz, join(", ", #atz));
All tz names [349] = Africa/Abidjan, Africa/Accra, Africa/Algiers, Africa/Bissau, Africa/Cairo, Africa/Casablanca, Africa/Ceuta, Africa/El_Aaiun, Africa/Johannesburg, Africa/Khartoum, Africa/Lagos, Africa/Maputo, Africa/Monrovia, Africa/Nairobi, Africa/Ndjamena, Africa/Tripoli, Africa/Tunis, Africa/Windhoek, America/Adak, America/Anchorage, America/Araguaina, America/Argentina/Buenos_Aires, America/Argentina/Catamarca, America/Argentina/Cordoba, America/Argentina/Jujuy, America/Argentina/La_Rioja, America/Argentina/Mendoza, America/Argentina/Rio_Gallegos, America/Argentina/Salta, America/Argentina/San_Juan, America/Argentina/San_Luis, America/Argentina/Tucuman, America/Argentina/Ushuaia, America/Asuncion, America/Atikokan, America/Bahia, America/Bahia_Banderas, America/Barbados, America/Belem, America/Belize, America/Blanc-Sablon, America/Boa_Vista, America/Bogota, America/Boise, America/Cambridge_Bay, America/Campo_Grande, America/Cancun, America/Caracas, America/Cayenne, America/Chicago, America/Chihuahua, America/Costa_Rica, America/Creston, America/Cuiaba, America/Curacao, America/Danmarkshavn, America/Dawson, America/Dawson_Creek, America/Denver, America/Detroit, America/Edmonton, America/Eirunepe, America/El_Salvador, America/Fortaleza, America/Glace_Bay, America/Godthab, America/Goose_Bay, America/Grand_Turk, America/Guatemala, America/Guayaquil, America/Guyana, America/Halifax, America/Havana, America/Hermosillo, America/Indiana/Indianapolis, America/Indiana/Knox, America/Indiana/Marengo, America/Indiana/Petersburg, America/Indiana/Tell_City, America/Indiana/Vevay, America/Indiana/Vincennes, America/Indiana/Winamac, America/Inuvik, America/Iqaluit, America/Jamaica, America/Juneau, America/Kentucky/Louisville, America/Kentucky/Monticello, America/La_Paz, America/Lima, America/Los_Angeles, America/Maceio, America/Managua, America/Manaus, America/Martinique, America/Matamoros, America/Mazatlan, America/Menominee, America/Merida, America/Metlakatla, America/Mexico_City, America/Miquelon, America/Moncton, America/Monterrey, America/Montevideo, America/Montreal, America/Nassau, America/New_York, America/Nipigon, America/Nome, America/Noronha, America/North_Dakota/Beulah, America/North_Dakota/Center, America/North_Dakota/New_Salem, America/Ojinaga, America/Panama, America/Pangnirtung, America/Paramaribo, America/Phoenix, America/Port-au-Prince, America/Port_of_Spain, America/Porto_Velho, America/Puerto_Rico, America/Rainy_River, America/Rankin_Inlet, America/Recife, America/Regina, America/Resolute, America/Rio_Branco, America/Santa_Isabel, America/Santarem, America/Santiago, America/Santo_Domingo, America/Sao_Paulo, America/Scoresbysund, America/Sitka, America/St_Johns, America/Swift_Current, America/Tegucigalpa, America/Thule, America/Thunder_Bay, America/Tijuana, America/Toronto, America/Vancouver, America/Whitehorse, America/Winnipeg, America/Yakutat, America/Yellowknife, Antarctica/Casey, Antarctica/Davis, Antarctica/DumontDUrville, Antarctica/Macquarie, Antarctica/Mawson, Antarctica/Palmer, Antarctica/Rothera, Antarctica/Syowa, Antarctica/Troll, Antarctica/Vostok, Asia/Almaty, Asia/Amman, Asia/Anadyr, Asia/Aqtau, Asia/Aqtobe, Asia/Ashgabat, Asia/Baghdad, Asia/Baku, Asia/Bangkok, Asia/Beirut, Asia/Bishkek, Asia/Brunei, Asia/Chita, Asia/Choibalsan, Asia/Colombo, Asia/Damascus, Asia/Dhaka, Asia/Dili, Asia/Dubai, Asia/Dushanbe, Asia/Gaza, Asia/Hebron, Asia/Ho_Chi_Minh, Asia/Hong_Kong, Asia/Hovd, Asia/Irkutsk, Asia/Jakarta, Asia/Jayapura, Asia/Jerusalem, Asia/Kabul, Asia/Kamchatka, Asia/Karachi, Asia/Kathmandu, Asia/Khandyga, Asia/Kolkata, Asia/Krasnoyarsk, Asia/Kuala_Lumpur, Asia/Kuching, Asia/Macau, Asia/Magadan, Asia/Makassar, Asia/Manila, Asia/Nicosia, Asia/Novokuznetsk, Asia/Novosibirsk, Asia/Omsk, Asia/Oral, Asia/Pontianak, Asia/Pyongyang, Asia/Qatar, Asia/Qyzylorda, Asia/Rangoon, Asia/Riyadh, Asia/Sakhalin, Asia/Samarkand, Asia/Seoul, Asia/Shanghai, Asia/Singapore, Asia/Srednekolymsk, Asia/Taipei, Asia/Tashkent, Asia/Tbilisi, Asia/Tehran, Asia/Thimphu, Asia/Tokyo, Asia/Ulaanbaatar, Asia/Urumqi, Asia/Ust-Nera, Asia/Vladivostok, Asia/Yakutsk, Asia/Yekaterinburg, Asia/Yerevan, Atlantic/Azores, Atlantic/Bermuda, Atlantic/Canary, Atlantic/Cape_Verde, Atlantic/Faroe, Atlantic/Madeira, Atlantic/Reykjavik, Atlantic/South_Georgia, Atlantic/Stanley, Australia/Adelaide, Australia/Brisbane, Australia/Broken_Hill, Australia/Currie, Australia/Darwin, Australia/Eucla, Australia/Hobart, Australia/Lindeman, Australia/Lord_Howe, Australia/Melbourne, Australia/Perth, Australia/Sydney, CET, CST6CDT, EET, EST, EST5EDT, Europe/Amsterdam, Europe/Andorra, Europe/Athens, Europe/Belgrade, Europe/Berlin, Europe/Brussels, Europe/Bucharest, Europe/Budapest, Europe/Chisinau, Europe/Copenhagen, Europe/Dublin, Europe/Gibraltar, Europe/Helsinki, Europe/Istanbul, Europe/Kaliningrad, Europe/Kiev, Europe/Lisbon, Europe/London, Europe/Luxembourg, Europe/Madrid, Europe/Malta, Europe/Minsk, Europe/Monaco, Europe/Moscow, Europe/Oslo, Europe/Paris, Europe/Prague, Europe/Riga, Europe/Rome, Europe/Samara, Europe/Simferopol, Europe/Sofia, Europe/Stockholm, Europe/Tallinn, Europe/Tirane, Europe/Uzhgorod, Europe/Vienna, Europe/Vilnius, Europe/Volgograd, Europe/Warsaw, Europe/Zaporozhye, Europe/Zurich, HST, Indian/Chagos, Indian/Christmas, Indian/Cocos, Indian/Kerguelen, Indian/Mahe, Indian/Maldives, Indian/Mauritius, Indian/Reunion, MET, MST, MST7MDT, PST8PDT, Pacific/Apia, Pacific/Auckland, Pacific/Bougainville, Pacific/Chatham, Pacific/Chuuk, Pacific/Easter, Pacific/Efate, Pacific/Enderbury, Pacific/Fakaofo, Pacific/Fiji, Pacific/Funafuti, Pacific/Galapagos, Pacific/Gambier, Pacific/Guadalcanal, Pacific/Guam, Pacific/Honolulu, Pacific/Kiritimati, Pacific/Kosrae, Pacific/Kwajalein, Pacific/Majuro, Pacific/Marquesas, Pacific/Nauru, Pacific/Niue, Pacific/Norfolk, Pacific/Noumea, Pacific/Pago_Pago, Pacific/Palau, Pacific/Pitcairn, Pacific/Pohnpei, Pacific/Port_Moresby, Pacific/Rarotonga, Pacific/Tahiti, Pacific/Tarawa, Pacific/Tongatapu, Pacific/Wake, Pacific/Wallis, UTC, WET