当前位置: 首页 > 工具软件 > libPhenom > 使用案例 >

libPhenom 编译

龙欣德
2023-12-01

 安装 http://c-ares.haxx.se/

安装 http://concurrencykit.org/

编译步骤:

$ ./autogen.sh
$ ./configure
$ make
$ make check
$ sudo make install
[root@s3 libphenom-master]# ./configure 
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking dependency style of gcc... gcc3
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1966080
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for ar... ar
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking dependency style of gcc... (cached) gcc3
checking whether byte ordering is bigendian... no
checking for inline... inline
checking whether gcc and cc understand -c and -o together... yes
checking dependency style of gcc... gcc3
checking for library containing pthread_create... -lpthread
checking for library containing socket... none required
checking for library containing clock_gettime... -lrt
checking for library containing inet_pton... none required
checking for python... /usr/bin/python
checking for pkg-config... /usr/bin/pkg-config
checking for php... /usr/bin/php
checking alloca.h usability... yes
checking alloca.h presence... yes
checking for alloca.h... yes
checking for inttypes.h... (cached) yes
checking locale.h usability... yes
checking locale.h presence... yes
checking for locale.h... yes
checking port.h usability... no
checking port.h presence... no
checking for port.h... no
checking pthread.h usability... yes
checking pthread.h presence... yes
checking for pthread.h... yes
checking stdbool.h usability... yes
checking stdbool.h presence... yes
checking for stdbool.h... yes
checking stddef.h usability... yes
checking stddef.h presence... yes
checking for stddef.h... yes
checking for stdint.h... (cached) yes
checking for string.h... (cached) yes
checking sys/inotify.h usability... yes
checking sys/inotify.h presence... yes
checking for sys/inotify.h... yes
checking sys/epoll.h usability... yes
checking sys/epoll.h presence... yes
checking for sys/epoll.h... yes
checking sys/event.h usability... no
checking sys/event.h presence... no
checking for sys/event.h... no
checking sys/eventfd.h usability... yes
checking sys/eventfd.h presence... yes
checking for sys/eventfd.h... yes
checking sys/param.h usability... yes
checking sys/param.h presence... yes
checking for sys/param.h... yes
checking sys/processor.h usability... no
checking sys/processor.h presence... no
checking for sys/processor.h... no
checking sys/procset.h usability... no
checking sys/procset.h presence... no
checking for sys/procset.h... no
checking sys/resource.h usability... yes
checking sys/resource.h presence... yes
checking for sys/resource.h... yes
checking sys/timerfd.h usability... yes
checking sys/timerfd.h presence... yes
checking for sys/timerfd.h... yes
checking for sys/cpuset.h... no
checking for pthread_np.h... no
checking for accept4... yes
checking for asprintf... yes
checking for backtrace... yes
checking for backtrace_symbols... yes
checking for backtrace_symbols_fd... yes
checking for clock_gettime... yes
checking for cpuset_setaffinity... no
checking for epoll_create... yes
checking for epoll_create1... yes
checking for getpagesize... yes
checking for inotify_init... yes
checking for kqueue... no
checking for localeconv... yes
checking for pipe2... yes
checking for port_create... no
checking for processor_bind... no
checking for pthread_getname_np... yes
checking for pthread_set_name_np... no
checking for pthread_setname_np... yes
checking for pthread_setaffinity_np... yes
checking for pthread_mach_thread_np... no
checking for strerror_r... yes
checking for strtoll... yes
checking for sysctlbyname... no
checking for thread_policy_set... no
checking for timerfd_create... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating libphenom.pc
config.status: creating include/phenom_build_config.h
config.status: include/phenom_build_config.h is unchanged
config.status: creating include/phenom/feature_test.h
config.status: include/phenom/feature_test.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands


错误1:

修改cpplint.py, def CheckForHeaderGuard(filename, lines, error):

原因:未知,github上下载的最新代码, 不过这个可以忽略。

直接return


[root@s3 libphenom-master]# make install
./thirdparty/clint.sh
include/phenom/stream.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_STREAM_H  [build/header_guard] [5]
corelib/log.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_CORELIB_LOG_H  [build/header_guard] [5]
include/phenom/memory.h:24:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_MEMORY_H  [build/header_guard] [5]
corelib/counter.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_CORELIB_COUNTER_H  [build/header_guard] [5]
corelib/gimli/gimli.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_CORELIB_GIMLI_GIMLI_H  [build/header_guard] [5]
include/phenom/variant.h:284:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_VARIANT_H  [build/header_guard] [5]
include/phenom/dns.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_DNS_H  [build/header_guard] [5]
corelib/job.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_CORELIB_JOB_H  [build/header_guard] [5]
include/phenom/timerwheel.h:41:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_TIMERWHEEL_H  [build/header_guard] [5]
include/phenom/printf.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_PRINTF_H  [build/header_guard] [5]
include/phenom/counter.h:78:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_COUNTER_H  [build/header_guard] [5]
include/phenom/job.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_JOB_H  [build/header_guard] [5]
include/phenom/configuration.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_CONFIGURATION_H  [build/header_guard] [5]
include/phenom/json.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_JSON_H  [build/header_guard] [5]
include/phenom/defs.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_DEFS_H  [build/header_guard] [5]
include/phenom/hook.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_HOOK_H  [build/header_guard] [5]
include/phenom/listener.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_LISTENER_H  [build/header_guard] [5]
include/phenom/thread.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_THREAD_H  [build/header_guard] [5]
include/phenom/socket.h:18:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_SOCKET_H  [build/header_guard] [5]
include/phenom/refcnt.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_REFCNT_H  [build/header_guard] [5]
include/phenom/string.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_STRING_H  [build/header_guard] [5]
include/phenom/log.h:64:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_LOG_H  [build/header_guard] [5]
include/phenom/openssl.h:18:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_OPENSSL_H  [build/header_guard] [5]
include/phenom/sysutil.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_SYSUTIL_H  [build/header_guard] [5]
include/phenom/buffer.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_BUFFER_H  [build/header_guard] [5]
include/phenom/hashtable.h:17:  #ifndef header guard has wrong style, please use: _HOME_DOG_TEST_LIBPHENOM_MASTER_INCLUDE_PHENOM_HASHTABLE_H  [build/header_guard] [5]
make: *** [check-lint] Error 123



错误2:

test.c:2:25: error: phenom/defs.h: No such file or directory
test.c:3:34: error: phenom/configuration.h: No such file or directory
test.c:4:24: error: phenom/job.h: No such file or directory
test.c:5:24: error: phenom/log.h: No such file or directory
test.c:6:28: error: phenom/sysutil.h: No such file or directory
test.c: In function ‘main’:
test.c:11: warning: implicit declaration of function ‘ph_library_init’
test.c:13: warning: implicit declaration of function ‘ph_config_load_config_file’
test.c:15: warning: implicit declaration of function ‘ph_nbio_init’
test.c:24: warning: implicit declaration of function ‘ph_debug_console_start’
test.c:27: warning: implicit declaration of function ‘ph_sched_run’



原因:libphenom.pc 被复制到了/usr/local/lib/pkgconfig/ 目录, 实际起作用的是  /usr/lib64/pkgconfig

解决办法:\cp /usr/local/lib/pkgconfig/libphenom.pc /usr/lib64/pkgconfig

错误3

编译:

gcc -O2 main.c `pkg-config libphenom --cflags --libs`

[root@s3 libphenom-master]# ./a.out
./a.out: error while loading shared libraries: libphenom.so.0: cannot open shared object file: No such file or directory

原因:共享库文件安装到了/usr/local/lib(很多开源的共享库都会安装到该目录下)或其它"非/lib或/usr/lib"目录下。

解决办法:

# echo "/usr/local/lib" >> /etc/ld.so.conf
# ldconfig

------------------------------------------------------------------------------------------------------------------------------------------------------------


// Always include phenom/defs.h first to correctly set up the compilation env
#include "phenom/defs.h"
#include "phenom/configuration.h"
#include "phenom/job.h"
#include "phenom/log.h"
#include "phenom/sysutil.h"

int main(int argc, char **argv)
{
  // Must be called prior to calling any other phenom functions
  ph_library_init();
  // Optional config file for tuning internals
  ph_config_load_config_file("/path/to/my/config.json");
  // Enable the non-blocking IO manager
  ph_nbio_init(0);

  // Do stuff here to register client/server stuff.
  // This enables a very simple request/response console
  // that allows you to run diagnostic commands:
  // `echo memory | nc -UC /tmp/phenom-debug-console`
  // (on BSD systems, use `nc -Uc`!)
  // The code behind this is in
  // https://github.com/facebook/libphenom/blob/master/corelib/debug_console.c
  ph_debug_console_start("/tmp/phenom-debug-console");

  // Run
  ph_sched_run();

  return 0;
}


运行结果:


[root@s3 pig]# echo memory | nc -UC /tmp/phenom-debug-console
                        WHAT     BYTES       OOM    ALLOCS     FREES   REALLOC
             threadpool/pool      9536         0         1         0         0 
          threadpool/ringbuf      8192         0         2         0         0 
             hashtable/table      2880         0         2         0         0 
                   hook/hook         0         0         0         0         0 
                   hook/head         0         0         0         0         0 
                 hook/string         0         0         0         0         0 
                  hook/unreg         0         0         0         0         0 
               stream/stream       272         0         2         0         0 
               buffer/object       120         0         3         0         0 
                   buffer/8k     16384         0         2         0         0 
                  buffer/16k         0         0         0         0         0 
                  buffer/32k         0         0         0         0         0 
                  buffer/64k         0         0         0         0         0 
                buffer/vsize         0         0         0         0         0 
                buffer/queue        48         0         2         0         0 
            buffer/queue_ent        64         0         2         0         0 
                dns/addrinfo         0         0         0         0         0 
                  dns/string         0         0         0         0         0 
             socket/listener       352         0         1         0         0 
          socket/connect_job         0         0         0         0         0 
                 socket/sock       704         0         1         0         0 
  socket/resolve_and_connect         0         0         0         0         0 
               stream/string         0         0         0         0         0 
               string/string         0         0         0         0         0 
                variant/json         0         0         0         0         0 
             variant/variant         0         0         0         0         0 
               variant/array         0         0         0         0         0 
             nbio/affine_job         0         0         0         0         0 

系统环境:

[root@s3 pig]# cat /etc/issue 
CentOS release 6.4 (Final)
Kernel \r on an \m


[root@s3 pig]# gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) 



 类似资料: