Agamnentzar / bluetooth-serial-port

multi-platform bluetooth serial port library for C++
Other
89 stars 27 forks source link

Linker Issues on Windows #18

Open AndyHud411 opened 3 years ago

AndyHud411 commented 3 years ago

Hello everyone, I am having difficulties getting this library to work. I am currently using Visual Studio 2019. I have looked in a past thread about this same problem pretty much but when I followed that answer it did not work. My Errors:

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "public: thiscall DeviceINQ::~DeviceINQ(void)" (??1DeviceINQ@@QAE@XZ) referenced in function "public: void * thiscall DeviceINQ::`scalar deleting destructor'(unsigned int)" (??_GDeviceINQ@@QAEPAXI@Z) PleaseSerialWork C:\Users\Swagm\source\repos\PleaseSerialWork\PleaseSerialWork\PleaseSerialWork.obj 1
Error LNK2019 unresolved external symbol "public: static class DeviceINQ * __cdecl DeviceINQ::Create(void)" (?Create@DeviceINQ@@SAPAV1@XZ) referenced in function _main PleaseSerialWork C:\Users\Swagm\source\repos\PleaseSerialWork\PleaseSerialWork\PleaseSerialWork.obj 1
Error LNK2019 unresolved external symbol "public: class std::vector<struct device,class std::allocator > __thiscall DeviceINQ::Inquire(int)" (?Inquire@DeviceINQ@@QAE?AV?$vector@Udevice@@V?$allocator@Udevice@@@std@@@std@@H@Z) referenced in function _main PleaseSerialWork C:\Users\Swagm\source\repos\PleaseSerialWork\PleaseSerialWork\PleaseSerialWork.obj 1
Error LNK1120 3 unresolved externals PleaseSerialWork C:\Users\Swagm\source\repos\PleaseSerialWork\Debug\PleaseSerialWork.exe 1

Here is a bit more info. (Additional Includes) : C:\Users\Swagm\bluetooth-serial-port\src

(Additional Libraries in Linker) : C:\Users\Swagm\bluetooth-serial-port\Debug\bluetoothserialport.lib

I have tried everything. I really hope I can get this working because this utility would be insanely useful for my current project. Thank you so much in advanced.

Agamnentzar commented 3 years ago

I can't really help with provided information, there might be some wrong configuration in visual studio that results in symbol mismatch.

I recommend just adding the library files into your project and compiling everything together, you won't have any linking issues in that case, just be sure to add these two libraries to linker ws2_32 bthprops

AndyHud411 commented 3 years ago

I can't really help with provided information, there might be some wrong configuration in visual studio that results in symbol mismatch.

I recommend just adding the library files into your project and compiling everything together, you won't have any linking issues in that case, just be sure to add these two libraries to linker ws2_32 bthprops

Thank you so much! Finally got it to work... Now I am having a problem connecting to devices. What is the prerequisite for connecting two devices? Is all they need to be connected to one another through bluetooth? Is the BTSerialPortBinding->Connect(address, Id) taking care of opening a RFCOMM port? or is that something I have to do manually?

Agamnentzar commented 3 years ago

yes, you should be able to just Read and Write data after Connect, you might also need to pass value of 1 as channelID

AndyHud411 commented 3 years ago

yes, you should be able to just Read and Write data after Connect, you might also need to pass value of 1 as channelID

Finally got it to connect (I Think) but I cannot get anything to read data? It does not seem to be reading anything from the port. It just sits and does nothing. Which I am assuming it is stalling till there is information in the buffer. My functions for sending information looks like this.

`int main() {

unique_ptr<DeviceINQ> inq(DeviceINQ::Create());
vector<device> devices = inq->Inquire();

cout << "--DEVICES--" << endl;
for (const auto& d : devices)
{
    cout << d.name << " " << d.address << endl;

}

string deviceName;

cout << "Enter device name to connect to: ";
getline(cin, deviceName);

//deviceName.pop_back();
cout << endl;
cout << "You Chose: " << deviceName << endl;

char buffer[20];

strcpy_s(buffer, "123451234512345");

cout << buffer << endl;

for (const auto& d : devices)
{
    if (d.name == deviceName)
    {
        try {
            unique_ptr<BTSerialPortBinding> port(BTSerialPortBinding::Create(d.address, 1));
            cout << "Is Connected : " << d.connected << endl;

                port->Connect();
                cout << "Connected" << endl;

                while (true)
                {
                    string trash;
                    getline(cin, trash);
                    port->Write(buffer, (int)strlen(buffer));
                    cout << "DID" << endl;
                }
        }
        catch (BluetoothException msg) {
            cout << msg.what();
        }
        break;
    }
}

cout << "No Devices Found...";

}`

and Receiving.

`int main() { std::cout << "Hello World!\n";

unique_ptr<DeviceINQ> inq(DeviceINQ::Create());
vector<device> devices = inq->Inquire();

cout << "--DEVICES--" << endl;
for (const auto& d : devices)
{
    cout << d.name << " " << d.address << endl;

}

string deviceName;

cout << "Enter device name to connect to: ";
getline(cin, deviceName);

//deviceName.pop_back();
cout << endl;
cout << "You Chose: " << deviceName << endl;

char buffer[20];

strcpy_s(buffer, "123451234512345");

cout << buffer << endl;

for (const auto& d : devices)
{
    if (d.name == deviceName)
    {
        try {
            unique_ptr<BTSerialPortBinding> port(BTSerialPortBinding::Create(d.address, 1));
            cout << "Is Connected : " << d.connected << endl;

                port->Connect();
                cout << "Connected" << endl;
                                    char buffor[20];
                while (true)
                {

                    cout << "Tried" << endl;
                    port->Read(buffer, 20);
                                            string boi = buffor;
                    cout << boi << endl;
                }
        }
        catch (BluetoothException msg) {
            cout << msg.what();
        }
        break;
    }
}

cout << "No Devices Found...";

}`

Thanks for all your help again.

Agamnentzar commented 3 years ago

Everything looks correct, not sure what might be the issue, are you sure the device is going to send data straight after connection ?

AndyHud411 commented 3 years ago

Everything looks correct, not sure what might be the issue, are you sure the device is going to send data straight after connection ?

I think so, the Bluetooth on my devices has been weird and didn't want to stay connected normally for some reason. Eventually it did, and the ::Connect() started working... When I write to the buffer it doesn't give me an error most of the time. But read just sits and does nothing.

AndyHud411 commented 3 years ago

What do you mean "Straight After connection" I connect them then I write data to the buffer. Then the already connected other end calls the read function. Does it matter if you call the read function before or after the data is sent?

Agamnentzar commented 3 years ago

Just meant it in the sense that some devices require some input before they start sending anything back, but I don't know what kind of device you're connecting to and if it's expected to send continuous data by itself

AndyHud411 commented 3 years ago

Just meant it in the sense that some devices require some input before they start sending anything back, but I don't know what kind of device you're connecting to and if it's expected to send continuous data by itself

Oh, well I am connecting two Windows PC's together with this code. So one end is doing the listening and the other end is doing the sending. I believe I don't need continuous data. Do you know of a way to check that though?

Agamnentzar commented 3 years ago

Oh, I don't have any experience with connecting 2 PCs that way, not sure if that requires any additional setup. I think one of them might have to be setup as server and serve RFCOMM service I don't know if you can just connect from both side peer to peer. I only ever used this to communicated with bluetooth devices that expose RFCOMM on their bluetooth.

AndyHud411 commented 3 years ago

How do you get the makefile to work in linux? Once you write code in linux how do you compile it with the makefile generated? Is there a place to add my file?

AndyHud411 commented 3 years ago

The code is not compiling a lot of the C libraries and I cannot seem to find why...

Agamnentzar commented 3 years ago

running

cmake .
make

seems to compile it fine on linux

Agamnentzar commented 3 years ago

you can also run make inquiretest to build test executable

AndyHud411 commented 3 years ago

you can also run make inquiretest to build test executable

Awesome! Thank you so much it is working... Sorta. Now it only shows the devices on occasion when they are connected. The test doesn't show any items. If you have any ideas let me know.

AndyHud411 commented 3 years ago

you can also run make inquiretest to build test executable

Awesome! Thank you so much it is working... Sorta. Now it only shows the devices on occasion when they are connected. The test doesn't show any items. If you have any ideas let me know.

Found out what the problem was. The DeviceINQ->Inq function only shows the devices that are not currently connected and are sharing their connection. Now my problem is I cannot read or write :C