Git Product home page Git Product logo

Comments (6)

jiejieTop avatar jiejieTop commented on July 20, 2024 1

注意:动态库的配置文件根据./test/mqtt_config.h配置的,在编译的时候就应该设置修改好配置文件~

from mqttclient.

jiejieTop avatar jiejieTop commented on July 20, 2024

我没有将test目录下的mqtt_config.h文件考到头文件目录下,你可以手动将它放过去,然后编译~

路径如下:https://github.com/jiejieTop/mqttclient/blob/master/test/mqtt_config.h

from mqttclient.

ihidchaos avatar ihidchaos commented on July 20, 2024

您好,依照指示复制了头文件

sudo cp -r test/mqtt_config.h /usr/include/
再次编译报错,

====================[ Build | app | Debug ]=====================================
/usr/bin/cmake --build /mnt/e/linux_c/cmake-build-debug --target app -- -j 8
Scanning dependencies of target app
[ 50%] Building C object CMakeFiles/app.dir/test.c.o
[100%] Linking C executable app
CMakeFiles/app.dir/test.c.o: In function topic1_handler': /mnt/e/linux_c/test.c:23: undefined reference to salof'
/mnt/e/linux_c/test.c:23: undefined reference to salof_get_tick' /mnt/e/linux_c/test.c:23: undefined reference to salof'
/mnt/e/linux_c/test.c:23: undefined reference to salof' /mnt/e/linux_c/test.c:23: undefined reference to salof'
/mnt/e/linux_c/test.c:24: undefined reference to salof' /mnt/e/linux_c/test.c:24: undefined reference to salof_get_tick'
/mnt/e/linux_c/test.c:24: undefined reference to salof' /mnt/e/linux_c/test.c:24: undefined reference to salof'
/mnt/e/linux_c/test.c:24: undefined reference to salof' /mnt/e/linux_c/test.c:25: undefined reference to salof'
/mnt/e/linux_c/test.c:25: undefined reference to salof_get_tick' /mnt/e/linux_c/test.c:25: undefined reference to salof'
/mnt/e/linux_c/test.c:25: undefined reference to salof' /mnt/e/linux_c/test.c:25: undefined reference to salof'
CMakeFiles/app.dir/test.c.o: In function mqtt_publish_thread': /mnt/e/linux_c/test.c:37: undefined reference to mqtt_list_subscribe_topic'
/mnt/e/linux_c/test.c:42: undefined reference to random_number' /mnt/e/linux_c/test.c:45: undefined reference to mqtt_publish'
/mnt/e/linux_c/test.c:48: undefined reference to mqtt_publish' /mnt/e/linux_c/test.c:51: undefined reference to mqtt_publish'
CMakeFiles/app.dir/test.c.o: In function main': /mnt/e/linux_c/test.c:65: undefined reference to salof_init'
/mnt/e/linux_c/test.c:71: undefined reference to test_ca_get' /mnt/e/linux_c/test.c:78: undefined reference to random_string'
/mnt/e/linux_c/test.c:79: undefined reference to random_string' /mnt/e/linux_c/test.c:80: undefined reference to random_string'
/mnt/e/linux_c/test.c:83: undefined reference to mqtt_init' /mnt/e/linux_c/test.c:85: undefined reference to mqtt_connect'
/mnt/e/linux_c/test.c:87: undefined reference to mqtt_subscribe' /mnt/e/linux_c/test.c:88: undefined reference to mqtt_subscribe'
/mnt/e/linux_c/test.c:89: undefined reference to mqtt_subscribe' /mnt/e/linux_c/test.c:91: undefined reference to pthread_create'
/mnt/e/linux_c/test.c:93: undefined reference to salof' /mnt/e/linux_c/test.c:93: undefined reference to salof_get_tick'
/mnt/e/linux_c/test.c:93: undefined reference to salof' /mnt/e/linux_c/test.c:93: undefined reference to salof'
/mnt/e/linux_c/test.c:93: undefined reference to `salof'
collect2: error: ld returned 1 exit status
CMakeFiles/app.dir/build.make:94: recipe for target 'app' failed
make[3]: *** [app] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/app.dir/all' failed
make[2]: *** [CMakeFiles/app.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/app.dir/rule' failed
make[1]: *** [CMakeFiles/app.dir/rule] Error 2
Makefile:118: recipe for target 'app' failed
make: *** [app] Error 2

查看mqtt_config.h,里面是一些用户自定义设置相关的宏,应该与上文的错误无关。
实在疑惑,求教这个错误原因?

from mqttclient.

jiejieTop avatar jiejieTop commented on July 20, 2024

@ihidchaos

嗯,是我的问题,现在已经修复了,重新操作一下:
1.克隆代码,./make-libmqttclient.sh编译库
2.进入libmqttclient目录,sudo cp -r include/* /usr/include/,复制头文件
3.编写cmakelist.txt代码,需要动态链接POSIX线程库

cmake_minimum_required(VERSION 3.10)
project(linux_c C)
set(CMAKE_C_STANDARD 11)
link_libraries(mqttclient)
find_package("Threads")
link_libraries(${CMAKE_THREAD_LIBS_INIT})
add_executable(app test.c)

修复的内容主要是,能正确编译动态库、将./test/mqtt_config.h也放到了头文件中。

from mqttclient.

ihidchaos avatar ihidchaos commented on July 20, 2024

感谢您的回复和帮助。按照您的提示,问题已经解决。
一点建议:./make-libmqttclient.sh安装库后也安装头文件;另外build.sh也加入make install选项。

from mqttclient.

jiejieTop avatar jiejieTop commented on July 20, 2024

感谢您的回复和帮助。按照您的提示,问题已经解决。
一点建议:./make-libmqttclient.sh安装库后也安装头文件;另外build.sh也加入make install选项。

我主要是考虑到直接安装头文件会污染系统的东西,而install 库比较容易管理,不过这些都不是啥事情哈,你解决就可以了

from mqttclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.