• C

undefined reference to `bswap_128'

I'm faced with following problem:

make.sh: line 2: $'\r': command not found
tagctl.c: In function ‘ble_send_command_wait_answer’:
tagctl.c:320:14: warning: unused variable ‘ntry’ [-Wunused-variable]
  int i, ret, ntry;
              ^
tagctl.c: In function ‘fwupdate_handler’:
tagctl.c:447:16: warning: unused variable ‘value’ [-Wunused-variable]
  unsigned char value[20], answer[20];
                ^
tagctl.c: At top level:
tagctl.c:51:13: warning: ‘dump_data’ defined but not used [-Wunused-function]
 static void dump_data(char *name, uint16_t handle, const uint8_t *data, int len)
             ^
tagctl.c:74:12: warning: ‘parse_hex’ defined but not used [-Wunused-function]
 static int parse_hex(char *s, uint8_t *value, int maxlen)
            ^
bluez/att.c: In function ‘put_uuid_le’:
bluez/att.c:47:3: warning: implicit declaration of function ‘bswap_128’ [-Wimplicit-function-declaration]
   bswap_128(&src->value.u128, dst);
   ^
bluez/gatt.c: In function ‘put_uuid_le’:
bluez/gatt.c:180:3: warning: implicit declaration of function ‘bswap_128’ [-Wimplicit-function-declaration]
   bswap_128(&uuid->value.u128, dst);
   ^
bluez/gattrib.c: In function ‘g_attrib_ref’:
bluez/gattrib.c:173:6: warning: variable ‘refs’ set but not used [-Wunused-but-set-variable]
  int refs;
      ^
bluez/gattrib.c: In function ‘can_write_data’:
bluez/gattrib.c:344:4: warning: implicit declaration of function ‘error’ [-Wimplicit-function-declaration]
    error("%s", gerr->message);
    ^
bluez/gattrib.c: In function ‘g_attrib_unregister’:
bluez/gattrib.c:713:3: warning: implicit declaration of function ‘warn’ [-Wimplicit-function-declaration]
   warn("%s: invalid id", __func__);
   ^
/tmp/ccWzwm20.o: In function `put_uuid_le':
att.c:(.text+0x8a): undefined reference to `bswap_128'
/tmp/ccWzwm20.o: In function `get_uuid':
att.c:(.text+0x2c9): undefined reference to `bswap_128'
/tmp/cc6AuWzK.o: In function `put_uuid_le':
gatt.c:(.text+0x373): undefined reference to `bswap_128'
/tmp/cc6AuWzK.o: In function `get_uuid128':
gatt.c:(.text+0x3da): undefined reference to `bswap_128'
collect2: error: ld returned 1 exit status
: numeric argument required

Open in new window


How to solve warning issues and undefined reference issues?


Thank you.
Nusrat NuriyevAsked:
Who is Participating?
 
evilrixSenior Software Engineer (Avast)Commented:
>> make.sh: line 2: $'\r': command not found
You seem to have Window's line endings in a file that is expecting Unix/Linux line endings. Try re-saving your file using an editor that understands Linux line endings (such as Programmers Notepad).

>> How to solve warning issues
Either:

1. add "-no-unused-variable" build flag to tell the compiler to ignore these (not my recommended solution)

2. Or comment out the unused variables

tagctl.c:320:14: warning: unused variable ‘ntry’ [-Wunused-variable]
  int i, ret, /* ntry */;

Open in new window


3. Or cast them to void after their definitions
  int i, ret, ntry;
(void) ntry; // don't warn about this being unused

Open in new window


>> and undefined reference issues?
You need to link to the library or object file that provides the function bswap_128. Unfortunately, you'll need to figure out what that is.
0
 
sarabandeCommented:
to add to above comment:

make.sh: line 2: $'\r': command not found
if you work at window for a unix platform you should choose a method for file transfer which removes the carriage-return characters from text files. a good way for example is to use svn at both sides for exchanging files (what additionally adds a backup to your developing). alternatively you may use a samba drive at unix where you store the files what also should solve the issue.

2. Or comment out the unused variables
yes, that is the recommended way. i often have found errors by 'unused' warnings which often give a valuable hint that an argument was not used (and probably could be removed) or that you used a different (wrong?) variable instead.

warning: implicit declaration of function ‘bswap_128’ [-Wimplicit-function-declaration]
   bswap_128(&src->value.u128, dst);
i would assume that you didn't include the header file where the bswap_128 was declared, or that your compiler found an ambiguous statement which it interpreted as a declaration (of a function) but actually was a function call. try to find the header where the bswap_128 was declared (and/or defined). alternatively you may implement the swapping operation explicit by means of  a helper variable.

Sara
0
 
Nusrat NuriyevAuthor Commented:
bswap_128 was simply commented out.
0
WEBINAR: 10 Easy Ways to Lose a Password

Join us on June 27th at 8 am PDT to learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees. We'll cover the importance of multi-factor authentication and how these solutions can better protect your business!

 
Nusrat NuriyevAuthor Commented:
Sara,
maybe git?
0
 
Nusrat NuriyevAuthor Commented:
Well, probably newline issue was appeared when some guy gave me the source code which was probably modified in windows. So, why this issue does not appear with gcc? because C compiler ignores whitespaces?

Does this issue appear with all files or mabe only with those which have been modified?
0
 
sarabandeCommented:
So, why this issue does not appear with gcc?
i had same issues with gcc as well. might have changed with newer versions. also make utility could handle line-endings differently between platforms.

maybe git?

i don't have used git myself, but surely any server-based versioning tool for bot windows and unix is able to handle windows line-ending issues properly. you even can write a tool yourself by code like (not tested)

#include <sys/stat.h>
#include <fstream>
#include <vector>
#include <algorithm>

int main(int nargs, char * szargs[])
{
    if (nargs < 3)
        return -1;
    struct stat fs = { 0 };
    if (!stat(szargs[1], &fs) || fs.st_size == 0)
        return -2;
    std::ifstream inputfile(szargs[1], std::ios::binary | std::ios::in);
    std::vector<unsigned char> input(fs.st_size, '\0');
    if (!inputfile.read((char*)&input[0], fs.st_size))
        return -3;
    inputfile.close();
    std::ofstream outputfile(szargs[2], std::ios::binary | std::ios::out);
    std::vector<unsigned char>::iterator n, f = input.begin();
    while ((f = std::find(f, input.end(), '\r')) != input.end())
    {
        n = f;
        if (*(++n) == '\n')
        {
            n = input.erase(f);
        }
        f = n;
    }
    if (input.empty())
        return -4;
    if (!outputfile.write((char*)&input[0], input.size()))
        return -5;
    outputfile.close();
    return 0;
} 

Open in new window

   

Does this issue appear with all files or mabe only with those which have been modified?

principially for windows text files (files opened in text mode) a pair of carriage-return/linefeed ("\r\n") would be written instead of a single linefeed character (what was made reverse when reading the file). since text files are written as streams any modified text file would have all line-endings that way. most windows editors were able to read unix text files properly but some "dump" applications, may complain or even ignore all the line-endings. a text file copied from a unix normally was not converted beside the source comes from a file server where your windows client would do the conversion. that is the case for example when using a drive mapped from a samba server and copy files by using the Windows Explorer. note, if you open the files in your program, you normally won't see any difference, beside you read the files in binary mode or use unicode character sets.

Sara
0
 
evilrixSenior Software Engineer (Avast)Commented:
Git can perform line ending conversion. It can be configured in various was to do this

https://help.github.com/articles/dealing-with-line-endings/
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.