Меню Рубрики

Linux undefined reference to

Компиляция проекта под Linux Ubuntu. Ошибка “undefined reference to”.

Вечер добрый! В общем опишу ситуацию: Есть набор файлов .c и .h. Есть скрипт makefile. Однако при попытке выполнить “make”, в терминале появляется следующий список сообщений:

/debug_tools$ make cc -fshort-enums -Wno-unused-result -lX11 -lm -pthread -ggdb -O0 -Wall -MD -MP -MF .dep/ui.o.d -c -o ui.o ui.c cc -fshort-enums -Wno-unused-result -lX11 -lm -pthread -ggdb -O0 -Wall -MD -MP -MF .dep/protocol.o.d -c -o protocol.o protocol.c cc -fshort-enums -Wno-unused-result -lX11 -lm -pthread -ggdb -O0 -Wall -MD -MP -MF .dep/graph.o.d -c -o graph.o graph.c cc -fshort-enums -Wno-unused-result -lX11 -lm -pthread -ggdb -O0 -Wall -MD -MP -MF .dep/gps.o.d -c -o gps.o gps.c cc -fshort-enums -Wno-unused-result -lX11 -lm -pthread -ggdb -O0 -Wall -MD -MP -MF .dep/ui.d ui.o fix.o protocol.o graph.o gps.o gnuplot_i.o -o ui graph.o: In function ‘graph_draw’: /home/jack/debug_tools/graph.c:53: undefined reference to ‘XSetForeground’ /home/jack/debug_tools/graph.c:56: undefined reference to ‘XDrawLine’ graph.o: In function ‘path_draw_point’: /home/jack/debug_tools/graph.c:90: undefined reference to ‘cos’ /home/jack/debug_tools/graph.c:91: undefined reference to ‘sin’ graph.o: In function ‘ui_func’: /home/jack/debug_tools/graph.c:242: undefined reference to ‘XFlush’ graph.o: In function ‘process_events’: /home/jack/debug_tools/graph.c:256: undefined reference to ‘XPending’ /home/jack/debug_tools/graph.c:258: undefined reference to ‘XNextEvent’ /home/jack/debug_tools/graph.c:261: undefined reference to ‘XKeycodeToKeysym’ graph.o: In function ‘ui_init’: /home/jack/debug_tools/graph.c:383: undefined reference to ‘XOpenDisplay’ /home/jack/debug_tools/graph.c:384: undefined reference to ‘XDisplayName’ /home/jack/debug_tools/graph.c:391: undefined reference to ‘XCreateSimpleWindow’ /home/jack/debug_tools/graph.c:395: undefined reference to ‘XSetStandardProperties’ /home/jack/debug_tools/graph.c:397: undefined reference to ‘XCreateGC’ /home/jack/debug_tools/graph.c:398: undefined reference to ‘XSetBackground’ /home/jack/debug_tools/graph.c:399: undefined reference to ‘XSetForeground’ /home/jack/debug_tools/graph.c:401: undefined reference to ‘XSelectInput’ /home/jack/debug_tools/graph.c:403: undefined reference to ‘XMapRaised’ /home/jack/debug_tools/graph.c:405: undefined reference to ‘XClearWindow’ /home/jack/debug_tools/graph.c:406: undefined reference to ‘XSync’ graph.o: In function ‘showtext’: /home/jack/debug_tools/graph.c:445: undefined reference to ‘XSetForeground’ /home/jack/debug_tools/graph.c:450: undefined reference to ‘XDrawImageString’ graph.o: In function ‘clear_wnd’: /home/jack/debug_tools/graph.c:454: undefined reference to ‘XSetForeground’ /home/jack/debug_tools/graph.c:455: undefined reference to ‘XFillRectangle’ /home/jack/debug_tools/graph.c:456: undefined reference to ‘XSetForeground’ /home/jack/debug_tools/graph.c:458: undefined reference to ‘XDrawLine’ /home/jack/debug_tools/graph.c:463: undefined reference to ‘XDrawLine’ /home/jack/debug_tools/graph.c:468: undefined reference to ‘XDrawLine’ /home/jack/debug_tools/graph.c:472: undefined reference to ‘XDrawLine’ graph.o: In function ‘setstat’: /home/jack/debug_tools/graph.c:480: undefined reference to ‘XSetForeground’ /home/jack/debug_tools/graph.c:481: undefined reference to ‘XFillRectangle’ collect2: выполнение ld завершилось с кодом возврата 1 make: *** [ui] Ошибка 1 jack@jack:

Дело в том, что с программированием под Linux не сталкивался раньше. Все сырцы писались другим человеком, который пропал бесследно. В итоге я застрял на этих вот ошибках. Вопрос: в какую сторону копать и что с ними делать (имею ввиду “undefined reference to”)?

Добавлено из комментария.

Вот содержание makefile:

uart_9bit и calib_edit собираются без проблем, а вот ui никак. make clean ничего не дает.

Источник

Ошибка при компилировании undefined reference to?

При компиляции вылетает указанная ниже ошибка. В чем может быть проблем? Linux
Часть кода
в шапке

тэг С++ относится к языку C++, то что у вас это Си.
то что вы компилируете этот код компилятором С++ не делает его кодом на С++.

При выполнение этого кода должен отправится POST запрос на IP адрес имеющегося оборудования с содержанием аудио файла в теле запроса.
Вот полный код программы:

Код был написан разработчиками оборудования, они утверждают, что он должен без проблем работать. В итоге были ошибки, я их исправил, но это не знаю как решить.

Евгений Шатунов, т.к в C++ я полный ноль, могу не понять некоторые вопросы.
Вообщем, как теперь я понял, никакого сценария у меня нет, я просто компилировал файл .cpp через компилятор Linux
g++ /dir/

Мне важно получить результат этого когда, но видимо я понятия не имею как это сделать.
Как было сказано автором, “скомпилируй в линуксе”

Код был написан разработчиками оборудования

Источник

Linux c++ error: undefined reference to ‘dlopen’

I work in Linux with C++ (Eclipse), and want to use a library. Eclipse shows me an error:

Do you know a solution?

10 Answers 10

You have to link against libdl, add

to your linker options

@Masci is correct, but in case you’re using C (and the gcc compiler) take in account that this doesn’t work:

Took me a bit to figure out.

The topic is quite old, yet I struggled with the same issue today while compiling cegui 0.7.1 (openVibe prerequisite).

What worked for me was to set: LDFLAGS=”-Wl,–no-as-needed” in the Makefile.

I’ve also tried -ldl for LDFLAGS but to no avail.

That’s one annoying “feature” for sure

I was struggling with it when writing heredoc syntax and found some interesting facts. With CC=Clang , this works:

as well as all of these:

  • $CC -ldl -x c -o app.exe –
  • $CC -x c -ldl -o app.exe –
  • $CC -x c -o app.exe -ldl –
  • $CC -x c -o app.exe – -ldl

However, with CC=gcc , only the last variant works; -ldl after – (the stdin argument symbol).

I was using CMake to compile my project and I’ve found the same problem.

The solution described here works like a charm, simply add $ to the target_link_libraries() call

you can try to add this

to the configure options

You needed to do something like this for the makefile:

That’ll pass the linker flags from make through to the linker. Doesn’t matter that the makefile was autogenerated.

I met the same problem even using -ldl .

Besides this option, source files need to be placed before libraries, see undefined reference to `dlopen’.

In order to use dl functions you need to use the -ldl flag for the linker.

how you do it in eclipse ?

Press Project –> Properties –> C/C++ build –> Settings –> GCC C++ Linker –>
Libraries –> in the “Libraries(-l)” box press the “+” sign –> write “dl” (without the quotes)-> press ok –> clean & rebuild your project.

Источник

Linux C++ make undefined reference to main

I’m working on a C++ project to refresh myself a little with the language and have run into what seem to be a rather strange (to me) issue when using make to build.

My project is setup with the following structure:

I’n src I’ve current got 2 files, loggerConfig.cpp and proxy.cpp. The main method is within proxy.cpp. My Makefile contains the following, which was taken from this post:

Everything works as expect unless I have a .cpp file in the same directory as my Makefile. Because I’m currently playing, before I put something into my project I’ll make a small standalone app within a test.cpp file. When I do that, and switch back to using make I’ll get the following error:

Simply moving the test.cpp file up one directory solves the problem and all compiles. Can anyone explain why? My understanding on make is fairly simple so I’m at a loss of what to Google for.

After running the find command for the SOURCES list directly in the shell I’ve found it’s not returning any results when the test.cpp file is present.

2 Answers 2

That’s a pretty fancy Makefile, and you may be causing yourself trouble by over-complicating it.

I would write this more like the following:

Perhaps I’m just a little old-school, but playing games with fancy variable substitutions is good fun until someone gets hurt, and when I give in to temptation there, I usually end up regretting it later, and simplifying the Makefile.

In particular, here are two further observations.

It seems unlikely that the set of sources is so very dynamic that it’s worth while generating the SOURCES variable on the fly. When you add a file, it’s no effort to add the name to the Makefile, and since the program won’t build if you don’t, there’s no danger of forgetting.

The @echo foo bar; foo bar pattern is surely just asking for trouble! At some point you are bound to adjust one of the foo bar parts without adjusting the other, and you are going to get very confused. Make echoes the lines it executes, unless you stop it with the @ prefix, so you seem to be synthesising the default behaviour by a roundabout route.

Источник


Adblock
detector