Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linker command failed with exit code 1 #16

Open
kaihirota opened this issue Apr 25, 2022 · 1 comment
Open

linker command failed with exit code 1 #16

kaihirota opened this issue Apr 25, 2022 · 1 comment

Comments

@kaihirota
Copy link

kaihirota commented Apr 25, 2022

I'm using UE4.26 on MacOS Monterey 12.2.1, with JetBrains Rider IDE.
The broker that I've set up is RabbitMQ hosted on AWS MQ.
I get the following error when I attempt to build by clicking on build button in the IDE:

Undefined symbols for architecture x86_64:
  "USpacesMarkerManager::rc", referenced from:
      USpacesMarkerManager::connect_callback(mosquitto*, void*, int) in SpacesMarkerManager.cpp.o
      USpacesMarkerManager::BeginSubscribe() in SpacesMarkerManager.cpp.o
ld: symbol(s) not found for architecture x86_64
0>clang: Error  : linker command failed with exit code 1 (use -v to see invocation)
Rebuild failed at 9:35:20 PM 

Code:

auto USpacesMarkerManager::connect_callback(struct mosquitto* mosq, void* obj, int result) -> void
{
	UE_LOG(LogTemp, Warning, TEXT("RabbitMQ Connection established: %d"), result);
	ResponseCode = result;
}

auto USpacesMarkerManager::message_callback(struct mosquitto* mosq, void* obj,
                                                  const struct mosquitto_message* message) -> void
{
	bool match = 0;
	FString Payload = FString((char*) message->payload);
	FString Topic = FString(message->topic);
	UE_LOG(LogTemp, Warning, TEXT("RabbitMQ Message Received: Payload: %s, Topic: %s"), *Payload, *Topic);
	
	mosquitto_topic_matches_sub("marker.dynamic.*", message->topic, &match);
	if (match) {
		UE_LOG(LogTemp, Warning, TEXT("Topic: %s Data: %s"), *Topic, *Payload);
	}

}

void USpacesMarkerManager::BeginSubscribe()
{
	mosquitto_lib_init();
	mosquitto* MqttClient = mosquitto_new("UE", false, 0);
	
	if (MqttClient)
	{
		mosquitto_connect_callback_set(MqttClient, &USpacesMarkerManager::connect_callback);
		mosquitto_message_callback_set(MqttClient, &USpacesMarkerManager::message_callback);
		
		ResponseCode = mosquitto_connect(
			MqttClient,
			"xxxxxxxx:xxxxxxxx*@xxx.ap-southeast-2.amazonaws.com",
			5671,
			60
		);
		mosquitto_subscribe(MqttClient, NULL, "*", 0);
		
		while(RunStatus){
			ResponseCode = mosquitto_loop(MqttClient, -1, 1);
			if(RunStatus && ResponseCode){
				UE_LOG(LogTemp, Warning, TEXT("RabbitMQ Connection Error"));
				sleep(10);
				mosquitto_reconnect(MqttClient);
			}
		}
		mosquitto_destroy(MqttClient);
	}
	mosquitto_lib_cleanup();
}

I would appreciate any insight on how I can resolve this build issue. TIA!

@kaihirota
Copy link
Author

kaihirota commented Apr 28, 2022

I found out the issue was caused by

mosquitto_connect_callback_set(MqttClient, &USpacesMarkerManager::connect_callback);

in particular, making any reference to static class variable caused the linker error, like using ResponseCode or RunStatus.

So my question is, how do you use mosquitto_loop if you can't use any references to variables outside of the callback function scope? Or if I'm mistaken, I would be grateful if someone could show me how you use reference to variables defined outside of the callback function scope. I want to use some kind of variable to control whether the subscription should continue or halt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant