analogdevicesinc / libiio

A cross platform library for interfacing with local and remote Linux IIO devices
http://analogdevicesinc.github.io/libiio/
GNU Lesser General Public License v2.1
483 stars 311 forks source link

Undefined C References in .so lib #1110

Closed illiw99 closed 7 months ago

illiw99 commented 8 months ago

Getting the following error message:

/usr/bin/ld: CMakeFiles/adis16460_example.dir/main.c.o: in function `main':
main.c:(.text+0x10): undefined reference to `iio_create_context_from_uri'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/adis16460_example.dir/build.make:104: adis16460_example] Error 1
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/adis16460_example.dir/all] Error 2
make: *** [Makefile:103: all] Error 2

Here is my minimum example

#include <stdio.h>
#include <iio.h>

int main(void) {

    struct iio_context *ctx;
    struct iio_device *dev0;

    ctx = iio_create_context_from_uri("ip:analog.local");

    if (!ctx) {
        perror("Unable to create IIO context");
        return -1;
    }

    dev0 = iio_context_find_device(ctx, "iio:device0");

    iio_context_destroy(ctx);

    return 0;
}
cmake_minimum_required(VERSION 3.10)
project(adis16460_example C)

set(CMAKE_C_STANDARD 11)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
find_package(LibIIO 1.0 REQUIRED)

add_executable(${PROJECT_NAME} main.c)

target_include_directories(${PROJECT_NAME} PUBLIC ${LibIIO_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PUBLIC ${LibIIO_LIBRARIES})

I removed the old libiio versions but still getting the error with current main branch.

Any help is much appreciated.

pcercuei commented 8 months ago

Well, that's an easy one. iio_create_context_from_uri is not in Libiio v1.0. Use iio_create_context instead.

IsaacSherman commented 3 weeks ago

OK, stupid question, but where do I get Libiio v1.0? All I can find are 0.x versions... I'm having the opposite problem. When I use the CSharp bindings, I get the error that the iio_create_context is not in the dll (and iio_create_context_from_uri IS in it, based on a dumpbin).

tfcollins commented 3 weeks ago

v1 is the main branch. No tags exist as it's not stable yet. Unless you need v1 features or are a developer it's recommended to use v0 releases