he4rt / scylladb-php-driver

PHP Driver for ScyllaDB/Apache Cassandra
Other
103 stars 25 forks source link

undefined symbol: cass_session_new when installing with libcassandra #106

Open ciaran-moore opened 1 day ago

ciaran-moore commented 1 day ago

When I install the extension to use the Datastax CPP-Driver, I receive the error undefined symbol: cass_session_new when trying to use the extension.

The installs are finding the correct headers as I can see the version info in the cassandra.h file as:

#define CASS_VERSION_MAJOR 2
#define CASS_VERSION_MINOR 17
#define CASS_VERSION_PATCH 1

And the extension build shows the version found as:

-- Checking for module 'cassandra'
--   Found cassandra, version 2.17.1

I can also see the symbol in the header being called and assigned to a CassSession*

/**
 * Creates a new session.
 *
 * @public @memberof CassSession
 *
 * @return Returns a session that must be freed.
 *
 * @see cass_session_free()
 */
CASS_EXPORT CassSession*
cass_session_new();

Install Steps:

# Install Datastax CPP Driver
## Clone Repo
git clone https://github.com/datastax/cpp-driver.git --recursive

## make build directory and enter
mkdir cpp-driver/build && cd cpp-driver/build

## Cmake the project
cmake -DCASS_CPP_STANDARD=17 -DCASS_BUILD_STATIC=ON -DCASS_BUILD_SHARED=ON -DCASS_USE_STD_ATOMIC=ON -DCASS_USE_TIMERFD=ON -DCASS_USE_LIBSSH2=ON -DCASS_USE_ZLIB=ON CMAKE_C_FLAGS="-fPIC" -DCMAKE_CXX_FLAGS="-fPIC -Wno-error=redundant-move" -DCMAKE_BUILD_TYPE="RelWithInfo" -G Ninja .. 
## Install
sudo ninja install

# Install PHP Driver
## Clone the Repo and enter
git clone https://github.com/he4rt/scylladb-php-driver.git --recursive && cd scylladb-php-driver

## Cmake the project
cmake --preset ReleaseLibCassandra -DPHP_SCYLLADB_USE_LIBCASSANDRA=ON -DPHP_SCYLLADB_LIBUV_STATIC=ON && cd out/ReleaseLibCassandra
## Install
sudo ninja install

Both build compile successfully, and cassandra module is loaded within php -m with no warnings

ciaran@test-server:/home/ciaran/scylladb-php-driver/out/Release$ php -m
[PHP Modules]
bcmath
brotli
bz2
calendar
cassandra

PHP Test Script

<?php

$cluster = [
  'name'      => 'test_cluster',
  'username'    => 'cassandra',
  'password'    => 'cassandra',
  'hosts'        => ['cassandra-n1', 'cassandra-n2'],
  'keyspace'    => 'system',
  'port'      => 9042,
];

$_cluster   = Cassandra::cluster([
        'default' => true,
        'name' => $cluster['name'],
        'hosts' => $cluster['hosts'],
        'username' => $cluster['username'],
        'password' => $cluster['password'],
        'port' => $cluster['port'],
        'keyspace' => $cluster['keyspace'],
        'datacenter' => 'dc1',
        'timeout' => 100,
        'connectTimeout' => 100,
        'requestTimeout' => 100
        ])                 // connects to localhost by default
         ->build();

$keyspace  = 'system';
$session   = $_cluster->connect($keyspace);        // create session, optionally scoped to a keyspace
$statement = new Cassandra\SimpleStatement(       // also supports prepared and batch statements
    'SELECT keyspace_name, columnfamily_name FROM schema_columnfamilies'
);
$querySent = $session->execute($statement);
$result    = $querySent->get();                      // wait for the result, with an optional timeout

foreach ($result as $row) {                       // results and rows implement Iterator, Countable and ArrayAccess
    printf("The keyspace %s has a table called %s\n", $row['keyspace_name'], $row['columnfamily_name']);
}

Run test script

ciaran@test-server:/home/ciaran$ php cassandra_test.php
php: symbol lookup error: /usr/lib/php/20230831/cassandra.so: undefined symbol: cass_session_new

Any ideas why this would be happening?

CodeLieutenant commented 1 day ago

This looks like to me it cannot find libcassandra.so the library that you have built from Datastax. can you please do ld cassandra.so, and paste the output here if you need any help.

cassandra.so -> PHP Driver and not libcassandra.so (the datastax driver)

Few suggestions to fix the issue