Installing DBI / DBD-Oracle with ActivePerl

本文介绍如何使用ActivePerl安装DBI/DBD-Oracle,并提供了一个用于测试安装是否成功的Perl脚本示例。

Installing DBI / DBD-Oracle with ActivePerl

by Jeff Hunter, Sr. Database Administrator

Overview

 

This article provides an overview on the steps required to install ActivePerl and DBI/DBD-Oracle (using Perl Package Manager). Also included in this article is a short Perl program that can be used to test the DBI/DBD installation with an Oracle database.

Download and Install ActivePerl

 

To start, you need to download a copy of ActivePerl. At the time of this writing, the highest release of ActivePerl is 5.8.3 (build 809), but there is no DBD-Oracle package for this release, and you will therefore need to download and install ActivePerl release 5.6.1.

NOTE: Until a DBD package is created for ActivePerl release 5.8.3, you will need to download the ActivePerl 5.6.1 (build 635) release.

You can download ActivePerl from the following location:

http://www.activestate.com/Products/Download/Download.plex?id=ActivePerl

NOTE: It is recommended that you use the MSI installer to install ActivePerl. The Windows AS Package provides NO uninstall functionality, and is recommended only if you are unable to install ActivePerl using the MSI installer.

The installation process for ActivePerl is a very straighforward process as long as you already have the "Windows Installer" service software installed. This service allows you to install, repair, and remove software according to instructions contained in .MSI files. To start the installation process, simply click the downloaded MSI file for ActivePerl: "ActivePerl-5.6.1.635-MSWin32-x86.msi" and follow the screen instructions.

For the purpose of this document, it is assumed that I installed ActivePerl in the directory: C:/Perl.

Download and Install DBI / DBD-Oracle

 

After successfully installing ActivePerl, it is time to download and install the DBI and DBD-Oracle packages using the Perl Package Manager (PPM) application. First, download the version of DBI and DBD-Oracle packages for the release of ActivePerl we are using: 5.6.1 from the following location:

http://ppm.activestate.com/PPMPackages/zips/

Download the two PPM Packages and put them in a temporary directory (i.e. C:/temp):

Once you have the two files into a temporary directory, unzip them:

C:/temp> unzip DBI-1.37.zip
C:/temp> unzip DBD-Oracle.zip
To install each of the packages, simply use the Perl Package Manager (PPM) application.

NOTE: You must install DBI BEFORE installing Oracle DBD !!!!

Installing DBI

 

C:/temp> ppm install DBI.ppd
Installing DBD

 

C:/temp> ppm install DBD-Oracle.ppd

Perl / Oracle Test Application

 

   Sample Oracle DBI Script. testDBDOracle_windows.pl
#!/usr/local/bin/perl

# +----------------------------------------------------------------------+
# | FILE         : testDBDOracle_windows.pl                              |
# | AUTHOR       : Jeff Hunter, Senior Database Administrator            |
# | PURPOSE      : This script will test the DBI/DBD installation.       |
# | OUTPUT FILES : NONE                                                  |
# +----------------------------------------------------------------------+

require "ctime.pl";
require "flush.pl";

use DBI;

&declareGlobalVariables;

&printHeader;

$dbh = &getOracleLogin("$ORACLE_SID", "$ORACLE_USERID", "$ORACLE_PASSWORD");
$dbh->{LongReadLen} = 64000;

&performTest;

&logoffOracle($dbh);

&printFooter;

exit;

# +--------------+
# | SUB ROUTINES |
# +--------------+
sub declareGlobalVariables {

  $ORACLE_SID              = "JEFFDB";
  $ORACLE_USERID           = "system";
  $ORACLE_PASSWORD         = "manager";

  $ENV{'ORACLE_SID'}       = "$ORACLE_SID";
  $ENV{'ORACLE_HOME'}      = "c://oracle//ora92";

}

sub printHeader {

  print "/n";
  print "Running testDBDOracle_windows.pl.../n";
  print "/n";

}

sub printFooter {

  print "Ending testDBDOracle_windows.pl.../n";
  print "/n";

}

sub getOracleLogin {

  local ($oracle_sid, $username, $password) = @_;
  local ($temp_dbh);
  local($tempID, $tempPassword, $tempKey);

  print "  (*) Attempting Oracle Login .../n";


  unless ( $temp_dbh = DBI->connect("dbi:Oracle:$oracle_sid", "$username", $password, {AutoCommit => 0}) ) {
    &programError("Oracle Login Failed as $username", "", "$DBI::errstr", "dba", "jhunter-pager");
    exit;
  }

  print "      OK/n/n";

  return $temp_dbh;

}

sub logoffOracle {

  ($dbh) = @_;

  print "  (*) Attempting Oracle Logoff .../n";

  unless ($dbh->disconnect) {

    # &programError("Could not disconnect from Oracle", "", "$DBI::errstr", "dba", "jhunter-pager");
    # exit;

    # Commented out this section because of the errors we get: ORA-02050
    # (some remote DBs may be in doubt (DBD: disconnect error)

    1;
  }

  print "      OK/n/n";

}

sub performTest {

  local ($rows1, $rows2, $rows3, $rows4);
  local ($test_dbi_intr_no, $test_dbi_name);
  local ($user, $sysdate);

  # +-----------------------+
  # | CREATE TABLE test_dbi |
  # +-----------------------+

  print "  (*) Creating table TEST_DBI .../n";

  $sql_statement = "
    CREATE TABLE test_dbi (
        test_dbi_intr_no    NUMBER(15)
      , test_dbi_name       VARCHAR2(100)
    )
  ";
  unless ($rows = $dbh->do("$sql_statement")) {
    &programError("Could not create table TEST_DBI", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  print "      OK/n/n";

  # +----------------------------+
  # | INSERT INTO TABLE test_dbi |
  # +----------------------------+

  print "  (*) Insert into TEST_DBI .../n";

  $sql_statement = "
    INSERT INTO test_dbi (
        test_dbi_intr_no
      , test_dbi_name
    ) VALUES (
        1000
      , 'Jeff Hunter'
    ) 
  ";

  unless ($rows1 = $dbh->do("$sql_statement")) {
    &programError("Could not do INSERT_TEST_DBI (Jeff) cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  print "      $rows1 rows inserted./n";

  $sql_statement = "
    INSERT INTO test_dbi (
        test_dbi_intr_no
      , test_dbi_name
    ) VALUES (
        1001
      , 'Melody Hunter'
    ) 
  ";

  unless ($rows2 = $dbh->do("$sql_statement")) {
    &programError("Could not do INSERT_TEST_DBI (Melody) cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  print "      $rows2 rows inserted./n";

  $sql_statement = "
    INSERT INTO test_dbi (
        test_dbi_intr_no
      , test_dbi_name
    ) VALUES (
        1002
      , 'Alex Hunter'
    ) 
  ";

  unless ($rows3 = $dbh->do("$sql_statement")) {
    &programError("Could not do INSERT_TEST_DBI (Alex) cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  print "      $rows3 rows inserted./n";

  unless ($dbh->commit) {
    &programError("Could not commit INSERT_TEST_DBI transaction", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  print "      OK/n/n";

  # +----------------------------+
  # | SELECT FROM TABLE test_dbi |
  # +----------------------------+

  print "  (*) Select from TEST_DBI .../n";

  $sql_statement = "
    SELECT
        test_dbi_intr_no
      , test_dbi_name
    FROM
        test_dbi
  ";

  unless ($cursor = $dbh->prepare("$sql_statement")) {
    &programError("Could not prepare SELECT_TEST_DBI cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  unless ($cursor->execute) {
   &programError("Could not execute SELECT_TEST_DBI cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
   $dbh->rollback;
   &logoffOracle($dbh);
   exit;
  }


  while ((   $test_dbi_intr_no
           , $test_dbi_name) = $cursor->fetchrow_array) {

    print "/n";
    print "        --> TEST_DBI_INTR_NO :  $test_dbi_intr_no/n";
    print "        --> TEST_DBI_NAME    :  $test_dbi_name/n";
    print "/n";

  }

  unless ($cursor->finish) {
   &programError("Could not finish SELECT_TEST_DBI cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
   $dbh->rollback;
   &logoffOracle($dbh);
   exit;
  }


  print "      OK/n/n";


  # +----------------------------+
  # | DELETE FROM TABLE test_dbi |
  # +----------------------------+

  print "  (*) Delete from TEST_DBI .../n";

  $sql_statement = "
    DELETE FROM test_dbi
  ";

  unless ($rows4 = $dbh->do("$sql_statement")) {
    &programError("Could not do DELETE_TEST_DBI (All Names) cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  print "      $rows4 rows deleted./n";

  unless ($dbh->commit) {
    &programError("Could not commit DELETE_TEST_DBI transaction", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  print "      OK/n/n";


  # +---------------------+
  # | DROP TABLE test_dbi |
  # +---------------------+

  print "  (*) Drop table TEST_DBI .../n";

  $sql_statement = "
    DROP TABLE test_dbi
  ";

  unless ($rows = $dbh->do("$sql_statement")) {
    &programError("Could not drop table TEST_DBI", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  print "      OK/n/n";


  # +-------------------+
  # | GET USER and DATE |
  # +-------------------+

  print "  (*) Select USER and SYSTEM .../n";

  $sql_statement = "
    SELECT
        user
      , TO_CHAR(sysdate, 'DD-MON-YYYY HH24:MI:SS')
    FROM
        dual
  ";

  unless ($cursor = $dbh->prepare("$sql_statement")) {
    &programError("Could not prepare SELECT_SINGLE cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  unless ($cursor->execute) {
   &programError("Could not execute SELECT_SINGLE cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
   $dbh->rollback;
   &logoffOracle($dbh);
   exit;
  }


  ($user, $sysdate) = $cursor->fetchrow_array;

  print "/n";
  print "        --> USER             :  $user/n";
  print "        --> SYSDATE          :  $sysdate/n";
  print "/n";

  unless ($cursor->finish) {
   &programError("Could not finish SELECT_SINGLE cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
   $dbh->rollback;
   &logoffOracle($dbh);
   exit;
  }

  print "      OK/n/n";

}


sub programError {

  local($message, $sql_statement, $ora_errstr, $email_who, $page_who) = @_;

  print "+--------------------------+/n";
  print "| SUB: programError        |/n";
  print "+--------------------------+/n";
  print "/n";

  unless($message) {$message = "No message provided from calling module.";}

  print "+-------------------------------------------------------+/n";
  print "| ******************* PROGRAM ERROR ******************* |/n";
  print "+-------------------------------------------------------+/n";
  print "/n";
  print "/n";
  print "Message:/n";
  print "--------------------------------------------------------/n";
  print "$message/n";
  print "/n";
  if ($sql_statement) {
    print "SQL:/n";
    print "--------------------------------------------------------/n";
    print "$sql_statement/n";
    print "/n";
  }

  if ($ora_errstr) {
    print "Oracle Error:/n";
    print "--------------------------------------------------------/n";
    print "$ora_errstr/n";
  }

  # +-------------------------------------+
  # | SEND THIS OUTPUT TO THE MAIL SYSTEM |
  # +-------------------------------------+

  if ($email_who) {

    $AUTO_MESSAGE = "/n";
    $AUTO_MESSAGE .= "+-------------------------------------------------------+/n";
    $AUTO_MESSAGE .= "| The following message was automatically               |/n";
    $AUTO_MESSAGE .= "| genereated by the Sysmon System.                      |/n";
    $AUTO_MESSAGE .= "+-------------------------------------------------------+/n";
    $AUTO_MESSAGE .= "/n";

    @EMAIL_ARRAY = split(/ /, $email_who);

    foreach (@EMAIL_ARRAY) {

      $TO = $_."/@fore.com";
      $FROM_FULL = "/"Sysmon Admin/"";
      $FROM = "/"dba/"";
      $Subject = "Sysmon Mail Error";

      open (MAIL,"|/usr/lib/sendmail -f $FROM -F $FROM_FULL $TO");
      print MAIL "To: $TO/n";
      print MAIL "From: $FROM/n";
      print MAIL "Reply-To: $FROM/n";
      print MAIL "Subject: $Subject/n/n";

      print MAIL "$AUTO_MESSAGE";

      print MAIL "+-------------------------------------------------------+/n";
      print MAIL "| ******************* PROGRAM ERROR ******************* |/n";
      print MAIL "+-------------------------------------------------------+/n";
      print MAIL "/n";
      print MAIL "/n";
      print MAIL "Message:/n";
      print MAIL "--------------------------------------------------------/n";
      print MAIL "$message/n";
      print MAIL "/n";
      if ($sql_statement) {
        print MAIL "SQL:/n";
        print MAIL "$sql_statement/n";
        print MAIL "--------------------------------------------------------/n";
        print MAIL "/n";
      }

      if ($ora_errstr) {
        print MAIL "Oracle Error:/n";
        print MAIL "--------------------------------------------------------/n";
        print MAIL "$ora_errstr/n";
      }

      close MAIL;
    }
  }

  if ($page_who) {

    @PAGER_ARRAY = split(/ /, $page_who);

    foreach (@PAGER_ARRAY) {

      $TO = $_."/@fore.com";
      $FROM_FULL = "/"Sysmon Admin/"";
      $FROM = "/"dba/"";
      $Subject = "Sysmon Program Error";

      open (MAIL,"|/usr/lib/sendmail -f $FROM -F $FROM_FULL $TO");
      print MAIL "To: $TO/n";
      print MAIL "From: $FROM/n";
      print MAIL "Reply-To: $FROM/n";
      print MAIL "Subject: $Subject/n/n";

      print MAIL "$message/n";
      close MAIL;
    }
  }

}
Install the project... -- Install configuration: "Release" -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/assert.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/avl-cmp.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/avl.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/blob.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/blobmsg.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/blobmsg_json.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/json_script.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/kvlist.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/list.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/md5.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/runqueue.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/safe_list.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/udebug-proto.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/udebug.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/ulog.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/uloop.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/usock.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/ustream.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/utils.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/vlist.h -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/libubox.so.20240329 -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/libubox.so -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/libubox.a -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/libblobmsg_json.so.20240329 -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/libblobmsg_json.so -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/libblobmsg_json.a -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/bin/jshn -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/libjson_script.so.20240329 -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/libjson_script.so -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/share/libubox/jshn.sh -- Installing: /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/lua/uloop.so make[4]: Leaving directory '/opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64' touch /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/.built rm -rf /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/.pkgdir/libubox.installed /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/.pkgdir/libubox mkdir -p /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/.pkgdir/libubox install -d -m0755 /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/.pkgdir/libubox/lib/ install -m0644 /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/libubox.so.* /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/.pkgdir/libubox/lib/ touch /opt/project/prplos1020/prplos/board/airoha_an75xx/sdk/er_phase2/prplos/prplos-v3.0.1/build_dir/target-aarch64_cortex-a53_musl/libubox-2024-03-29-eb9bcb64/.pkgdir/libubox.installed 上面编译时成功生成了.so.*文件 同样的编译文件,下面没有生成,请分析原因Install the project... -- Install configuration: "Release" -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/assert.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/avl-cmp.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/avl.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/blob.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/blobmsg.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/blobmsg_json.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/json_script.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/kvlist.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/list.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/md5.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/runqueue.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/safe_list.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/udebug-proto.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/udebug.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/ulog.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/uloop.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/usock.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/ustream.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/utils.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/include/libubox/vlist.h -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/libubox.so -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/libubox.a -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/libblobmsg_json.so -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/libblobmsg_json.a -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/bin/jshn -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/libjson_script.so -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/share/libubox/jshn.sh -- Installing: /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/lua/uloop.so make[5]: Leaving directory '/opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64' touch /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/.built rm -rf /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/.pkgdir/libubox.installed /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/.pkgdir/libubox mkdir -p /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/.pkgdir/libubox install -d -m0755 /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/.pkgdir/libubox/lib/ install -m0644 /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/libubox.so.* /opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/.pkgdir/libubox/lib/ install: cannot stat '/opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/ipkg-install/usr/lib/libubox.so.*': No such file or directory Makefile:117: recipe for target '/opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/.pkgdir/libubox.installed' failed make[4]: *** [/opt/project/prplos1020/prplos/board/qca_ipq53xx/sdk/12.2/build_dir/target-aarch64/libubox-2024-03-29-eb9bcb64/.pkgdir/libubox.installed] Error 1
最新发布
11-13
<think> 我们有两个编译日志:第一个成功,第二个失败。失败的原因是安装步骤中尝试复制libubox.so.*文件时找不到文件。 对比两个日志,我们发现: 成功案例(airoha_an75xx)中,安装步骤包含: -- Installing: .../ipkg-install/usr/lib/libubox.so.20240329 -- Installing: .../ipkg-install/usr/lib/libubox.so (符号链接) 失败案例(qca_ipq53xx)中,安装步骤只有: -- Installing: .../ipkg-install/usr/lib/libubox.so -- Installing: .../ipkg-install/usr/lib/libubox.a 注意:失败案例中没有生成带版本号的后缀文件(如libubox.so.20240329),因此后续步骤(复制libubox.so.*)失败。 原因分析: 1. 在成功案例中,编译生成的共享库文件带有版本号(如libubox.so.20240329),同时创建了一个无版本号的符号链接(libubox.so指向带版本号的库)。 2. 在失败案例中,只生成了无版本号的共享库文件(libubox.so)和静态库(libubox.a),没有带版本号的文件,也没有创建符号链接。因此,当尝试复制libubox.so.*时,没有匹配的文件。 为什么没有生成带版本号的共享库? 可能的原因: - 编译配置不同:可能第一个项目(airoha_an75xx)在配置中启用了版本化的共享库,而第二个项目(qca_ipq53xx)没有。 - 构建系统(如CMake)的配置差异:检查CMakeLists.txt中是否设置了版本号。 在libubox的构建系统中,通常会在CMakeLists.txt中设置库的版本。例如: set(LIBRARY_VERSION "20240329") add_library(ubox SHARED ...) set_target_properties(ubox PROPERTIES VERSION ${LIBRARY_VERSION} SOVERSION ${LIBRARY_VERSION}) 如果这个版本变量没有被设置,或者设置为空,那么就不会生成带版本号的库文件。 解决方案: 1. 检查构建配置:查看两个项目中libubox的CMake配置,确认是否设置了版本号。 2. 检查环境变量:可能在第二个项目中,构建时没有正确设置版本号。 3. 检查构建日志:在编译过程中,是否有关于设置库版本的输出。 另外,注意失败案例中,安装步骤没有生成带版本号的库,但是后续的打包步骤(在.pkgdir中)却试图复制带版本号的库(install -m0644 .../libubox.so.*),这显然会导致失败。 因此,需要调整打包步骤,使其能够兼容没有版本号的情况,或者确保在构建时生成版本号。 具体到OpenWrt的构建系统,可以检查libubox的Makefile(在package/feeds/packages/libubox/或类似位置)中是否正确地传递了版本信息。 临时解决方案: 在失败案例的构建目录中,可以尝试手动创建符号链接,但这不是根本解决办法。 根本解决办法: 1. 确保在配置阶段设置库版本号。 2. 修改打包脚本,使其在没有带版本号的库文件时,只复制无版本号的库文件。 但是,由于是同一个libubox源码,在两个不同的平台(airoha_an75xx和qca_ipq53xx)上构建,所以可能是平台特定的配置问题。 建议步骤: 1. 检查两个项目中libubox的编译配置(config.cmake或CMakeCache.txt),查看关于版本设置的变量。 2. 在失败项目中,尝试在编译之前设置版本号,例如: export LIBRARY_VERSION=20240329 3. 或者修改构建脚本(如果使用OpenWrt的package.mk),确保传递版本信息。 由于失败案例中,安装步骤只安装了libubox.so(而不是带版本号的文件),我们可以推断在编译时没有设置版本属性。因此需要检查构建系统。 另外,注意成功案例中,构建目录是:target-aarch64_cortex-a53_musl,而失败案例是:target-aarch64。这可能是不同的目标架构,但通常不会影响版本号的设置。 结论:问题在于第二个项目(qca_ipq53xx)在构建libubox时没有生成带版本号的共享库,导致后续打包步骤失败。 因此,需要检查第二个项目中libubox的构建配置,确保设置正确的版本号。 </think> ### 问题分析:共享库版本文件缺失的根本原因 从两个编译日志对比可以看出,关键差异在于共享库版本文件(如`libubox.so.20240329`)的生成与安装: #### 成功案例(airoha_an75xx): ```text -- Installing: .../libubox.so.20240329 -- Installing: .../libubox.so # 符号链接 ``` #### 失败案例(qca_ipq53xx): ```text -- Installing: .../libubox.so # 仅基础文件 install: cannot stat '.../libubox.so.*': No such file or directory ``` ### 根本原因分析 1. **共享库版本控制机制失效**: - CMake未正确生成带版本号的共享库文件(如`.so.20240329`) - 缺少版本文件导致后续`install -m0644 .../libubox.so.*`命令失败 2. **CMake配置差异**: ```cmake # 正确配置应包含版本设置 set_target_properties(ubox PROPERTIES VERSION ${PROJECT_VERSION} # 缺失此配置 SOVERSION ${PROJECT_API_VERSION} ) ``` 3. **构建环境差异**: - 目标架构不同:`aarch64_cortex-a53_musl` vs `aarch64` - 工具链配置可能导致版本符号链接生成失败 4. **安装脚本缺陷**: ```bash install -m0644 .../libubox.so.* # 未检查文件是否存在 ``` ### 解决方案 #### 方法1:修复CMake配置(推荐) 在`CMakeLists.txt`中确保包含: ```cmake project(libubox VERSION 2024.03.29) # 设置项目版本 add_library(ubox SHARED ${SOURCES}) set_target_properties(ubox PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION 1 # 或使用 ${PROJECT_VERSION_MAJOR} ) ``` #### 方法2:修改安装脚本 在Makefile中增加存在性检查: ```bash # 修改前 install -m0644 .../libubox.so.* ... # 修改后 if [ -f .../libubox.so.* ]; then install -m0644 .../libubox.so.* ... fi ``` #### 方法3:强制生成符号链接 在构建后步骤添加: ```bash cd ${LIBDIR} ln -sf libubox.so libubox.so.${VERSION} ``` ### 调试步骤 1. **检查构建产物**: ```bash find build_dir -name "libubox.so*" ``` 2. **验证CMake配置**: ```bash grep -r "VERSION" CMakeLists.txt ``` 3. **查看共享库属性**: ```bash readelf -d build_dir/target-*/libubox.so | grep SONAME ``` 4. **对比编译标志**: ```bash diff -u config1/CMakeCache.txt config2/CMakeCache.txt | grep "SHARED_LIB" ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值