CMakeLists.txt target_link_libraries is not linking my library [closed]

asked 2015-01-22 03:14:18 -0600

KDROS gravatar image

updated 2015-01-22 09:34:43 -0600

Tom Moore gravatar image

Its my same question with more details I have written code imu.cpp which is using ftdi library named libftd2xx. Code is given below

imu.cpp

  #include <ros/ros.h>
  #include <tf/transform_broadcaster.h>
  #include <nav_msgs/Odometry.h>
  #include <sensor_msgs/Imu.h>
   #include <stdio.h>
   #include <stdlib.h>
   #include <sys/time.h>
   #include <string.h>
   #include <unistd.h>
  #include <ftd2xx.h>
 using namespace std;
 int main(int argc, char** argv){
     ros::init(argc, argv, "First_node");

     ros::NodeHandle n;
      ros::Publisher imu_pub = n.advertise<sensor_msgs::Imu>("imu", 50);
     ros::Publisher odom_pub = n.advertise<nav_msgs::Odometry>("odom", 50);
    tf::TransformBroadcaster odom_broadcaster;
FT_STATUS   ftStatus;
FT_HANDLE   ftHandle;
DWORD BytesWritten;
DWORD EventDWord;
DWORD TxBytes;
DWORD RxBytes;
DWORD BytesReceived;
DWORD libraryVersion = 0;
int iport,len,i,direction=0,adjust;
unsigned char RxBuffer[30],outword[60];
int ch=1,c=0;
unsigned char TxBuffer13[]="\x4E\x45\x58\x90\x02\r\n"; // Set Mode 00 , 01,02
unsigned char TxBuffer[40]="\x4E\x45\x58",TxBuffer1[256]; // Contains data to write to device
unsigned char  data[40];
unsigned char TxBuffer16[]="\x4E\x45\x58\x9C\x00\x00\x02\x30\x01\x00\x00\x02\x30\x01\r\n"; // Set Position
unsigned char TxBufferA[]="\x4E\x45\x58\x9C\x00\x00\x00\x00\xFF\x00\x00\x00\x00\x01\r\n";
unsigned char TxBufferC[]="\x4E\x45\x58\x9C\x00\x00\x00\x00\x01\x00\x00\x00\x00\xFF\r\n";
unsigned char TxBuffer4[]="\x4E\x45\x58\x8C\x00\r\n"; // Clear Encoder Counts   
unsigned char c1,c2;
unsigned char sum,final_hex[10],hex[5],hex2[5]="0";

ftStatus = FT_GetLibraryVersion(&libraryVersion);
if (ftStatus == FT_OK)
{
    printf("Library version = 0x%x\n", (unsigned int)libraryVersion);
}
else
{
    printf("Error reading library version.\n");
    return 1;
}

if(argc > 1) {
    sscanf(argv[1], "%d", &iport);
}
else {
    iport = 0;
}
printf("Opening port %d\n", iport);

ftStatus = FT_Open(iport, &ftHandle);
if(ftStatus != FT_OK) {
    /* 
        This can fail if the ftdi_sio driver is loaded
        use lsmod to check this and rmmod ftdi_sio to remove
        also rmmod usbserial
     */
    printf("FT_Open(%d) failed\n", iport);
    return 1;
}

printf("FT_Open succeeded.  Handle is %p\n", ftHandle);

ftStatus = FT_SetBaudRate(ftHandle, 57600); // Set baud rate to 115200
if (ftStatus == FT_OK) {
    printf("\nFT_SetBaudRate OK");
}
else {
    printf("\nFT_SetBaudRate Failed");
}
// Set 8 data bits, 1 stop bit and no parity
ftStatus = FT_SetDataCharacteristics(ftHandle, FT_BITS_8, FT_STOP_BITS_1,
FT_PARITY_NONE);
if (ftStatus == FT_OK) {
printf("\nFT_SetDataCharacteristics OK");
}
else {
printf("\nFT_SetDataCharacteristics Failed");
}



    //Step 0. Clearing Counter
printf("\n Clearing Encoder Counts");
ftStatus = FT_Write(ftHandle, TxBuffer4, sizeof(TxBuffer4), &BytesWritten);
if (ftStatus == FT_OK) {
printf("\nFT_Write OK");
}
else {
printf("\nFT_Write Failed");
}
sleep(1);

    //Step 1. Setting Mode

printf("\n Setting Mode to Position Control");
ftStatus = FT_Write(ftHandle, TxBuffer13, sizeof(TxBuffer13), &BytesWritten);
if (ftStatus == FT_OK) 
{
    printf("\nFT_Write OK--> Setting Done \n\n");
}
else
{
    printf("\nSetting Mode Failed");
}






    //Step 3. Moving 0.5mt Forward

printf("\n\n MOVING fORWARD");
ftStatus = FT_Write(ftHandle, TxBuffer16, sizeof(TxBuffer16), &BytesWritten);
if (ftStatus == FT_OK) 
{
    printf("\n\n Stopped");
}
else 
{
    printf("\n Moving Failed");
}



   double x = 0.0;
   double y = 0.0;
   double th = 0.0;

   double vx = 0.1;
   double vy = -0.1;
   double vth = 0.1 ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant. Please see http://wiki.ros.org/Support for more details. by tfoote
close date 2015-03-12 15:59:43.822007

Comments

@Benny Re @Wolf @Devon W

KDROS gravatar image KDROS  ( 2015-01-22 04:00:25 -0600 )edit
1

Have you tried target_link_libraries(imu ${FTDI} ${catkin_LIBRARIES}) ?

BennyRe gravatar image BennyRe  ( 2015-01-22 05:26:24 -0600 )edit

@BennyRe but same error :-(

KDROS gravatar image KDROS  ( 2015-01-22 06:22:51 -0600 )edit
1

You said it's a C library right? Try the extern "C" declaration. http://www.oracle.com/technetwork/art...

BennyRe gravatar image BennyRe  ( 2015-01-26 02:10:22 -0600 )edit

I wrote C++ file and used this library with out extern "C", I think there is problem in Cmakelists.txt file.

KDROS gravatar image KDROS  ( 2015-01-28 01:24:53 -0600 )edit
1

I think it would be worth a try.

BennyRe gravatar image BennyRe  ( 2015-01-28 01:49:44 -0600 )edit

Closing as this isn't a ROS question. You need to find the right library and pass it to target_link_libraries. You should build using VERBOSE=1 to see what' being linked to help debug.

tfoote gravatar image tfoote  ( 2015-03-12 15:59:36 -0600 )edit