I have installed XQuartz.
I compiled using g++:
g++ -o -lX11 -I/opt/X11/include window2.cc
Error
Undefined symbols for architecture x86_64:
"_XCreateWindow", referenced from:
_main in window2-dXb9bZ.o
"_XFlush", referenced from:
_main in window2-dXb9bZ.o
"_XMapWindow", referenced from:
_main in window2-dXb9bZ.o
"_XOpenDisplay", referenced from:
_main in window2-dXb9bZ.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
If i compile like this:
g++ window2.cc -o window -lX11 -I/opt/X11/include
Error
ld: library not found for -lX11
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Im sure Xlib.h is in /opt/X11/include
Code:
#include <X11/Xlib.h>
#include <unistd.h>
int main()
{
// Open a display.
Display *d = XOpenDisplay(0);
if ( d )
{
// Create the window
Window w = XCreateWindow(d, DefaultRootWindow(d), 0, 0, 200,
100, 0, CopyFromParent, CopyFromParent,
CopyFromParent, 0, 0);
// Show the window
XMapWindow(d, w);
XFlush(d);
// Sleep long enough to see the window.
sleep(10);
}
return 0;
}
How do I solve this problem ? Thanks in advance
Problem resolved. In case anyone who's interested:
You have to compile like this:
g++ -o window window.cc -I/usr/X11R6/include -L/usr/X11R6/lib -lX11
Try
cc -I /opt/X11/include/ test.c -L /opt/X11/lib -lX11
Related
So I'm currently new to C right now, and I just downloaded the cs50 library. I tried to make an input by using get_int(), but it's not working. Here's my code:
#include <cs50.h>
#include <stdio.h>
int main(void)
{
int i = get_int("Input: ");
printf("Output: %i\n", i);
}
This is the error that I got
cc calculator.c -o calculator
Undefined symbols for architecture x86_64:
"_get_int", referenced from:
_main in calculator-225c65.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [calculator] Error 1
I am trying to compile a simple allegro5 program on Mac OSX 10.12 but am getting an undefined symbols error. Here is the command I ran in the terminal
gcc main.c -o hello -I/usr/local/include/ -L/usr/local/lib -lallegro_main
And here is my code.
#include <stdio.h>
#include <allegro5/allegro.h>
int main(int argc, char **argv)
{
ALLEGRO_DISPLAY *display = NULL;
if(!al_init())
{
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}
display = al_create_display(640, 480);
if(!display)
{
fprintf(stderr, "failed to create display!\n");
return -1;
}
al_clear_to_color(al_map_rgb(0,0,0));
al_flip_display();
al_rest(10.0);
al_destroy_display(display);
return 0;
}
Here is the error I get
Undefined symbols for architecture x86_64:
"_al_clear_to_color", referenced from:
__al_mangled_main in main-b86b99.o
"_al_create_display", referenced from:
__al_mangled_main in main-b86b99.o
"_al_destroy_display", referenced from:
__al_mangled_main in main-b86b99.o
"_al_flip_display", referenced from:
__al_mangled_main in main-b86b99.o
"_al_install_system", referenced from:
__al_mangled_main in main-b86b99.o
"_al_map_rgb", referenced from:
__al_mangled_main in main-b86b99.o
"_al_rest", referenced from:
__al_mangled_main in main-b86b99.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Is it possible that I did not install allegro correctly? I installed it using homebrew according to the allegro wiki instructions. https://wiki.allegro.cc/index.php?title=Getting_Started#Mac_OS
Those are linker errors. You need to link to lallegro.
I am trying to use the tidylib library within my C application. When compiling, I get the following errors:
$ make
rm -f sbo-export
cc sbo-export.c safarilib.c -L/usr/local/lib -lcurl -L/usr/local/Cellar/libtidy/lib -I/usr/local/Cellar/libtidy/include -o sbo-export
Undefined symbols for architecture x86_64:
"_tidyCreate", referenced from:
_safari_init_session in safarilib-c7ab6a.o
"_tidyParseString", referenced from:
_safari_init_session in safarilib-c7ab6a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [default] Error 1
safarilib.c:
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <tidy/tidy.h>
#include <tidy/buffio.h>
#include <curl/curl.h>
#include "safarilib.h"
void usage( char *username, char *password )
{
TidyDoc tdoc = tidyCreate();
char *input = "<html><body><h1>Hello World!</h1></body></html>";
tidyParseString( tdoc, input );
}
Any suggestions?
Further Infos:
For installing libtidy, I did the following:
Downloaded libtidy from http://tidy.sourceforge.net and then
followed the instructions form the file tidy/build/readme.txt
My library is installed here:
/usr/local/Cellar/libtidy
/usr/local/Cellar/libtidy/bin
/usr/local/Cellar/libtidy/bin/tab2space
/usr/local/Cellar/libtidy/bin/tidy
/usr/local/Cellar/libtidy/include
/usr/local/Cellar/libtidy/include/buffio.h
/usr/local/Cellar/libtidy/include/platform.h
/usr/local/Cellar/libtidy/include/tidy.h
/usr/local/Cellar/libtidy/include/tidyenum.h
/usr/local/Cellar/libtidy/lib
/usr/local/Cellar/libtidy/lib/libtidy-0.99.0.dylib
/usr/local/Cellar/libtidy/lib/libtidy.a
/usr/local/Cellar/libtidy/lib/libtidy.dylib
/usr/local/Cellar/libtidy/lib/libtidy.la
From compiler option it's look you have not specified tidylib.
cc sbo-export.c safarilib.c -L/usr/local/lib -lcurl -L/usr/local/Cellar/libtidy/lib -I/usr/local/Cellar/libtidy/include -o sbo-export
Here you need to add -ltidy and probably path by -L .
Some additional info about linking.
I downloaded bait from Scintilla's documentation page but whenever I try to compile it using the provided makefile, it fails with this error:
$ make
gcc `pkg-config --cflags gtk+-2.0` -I../scintilla/include -DGTK -DSCI_LEXER -W -Wall -c bait.c -o bait.o
gcc -DGTK bait.o ../scintilla/gtk/LexA68k.o ../scintilla/gtk/LexAPDL.o ../scintilla/gtk/LexASY.o ../scintilla/gtk/LexAU3.o ../scintilla/gtk/LexAVE.o ../scintilla/gtk/LexAVS.o ../scintilla/gtk/LexAbaqus.o ../scintilla/gtk/LexAda.o ../scintilla/gtk/LexAsm.o ../scintilla/gtk/LexAsn1.o ../scintilla/gtk/LexBaan.o ../scintilla/gtk/LexBash.o ../scintilla/gtk/LexBasic.o ../scintilla/gtk/LexBullant.o ../scintilla/gtk/LexCLW.o ../scintilla/gtk/LexCOBOL.o ../scintilla/gtk/LexCPP.o ../scintilla/gtk/LexCSS.o ../scintilla/gtk/LexCaml.o ../scintilla/gtk/LexCmake.o ../scintilla/gtk/LexCoffeeScript.o ../scintilla/gtk/LexConf.o ../scintilla/gtk/LexCrontab.o ../scintilla/gtk/LexCsound.o ../scintilla/gtk/LexD.o ../scintilla/gtk/LexDMAP.o ../scintilla/gtk/LexDMIS.o ../scintilla/gtk/LexECL.o ../scintilla/gtk/LexEScript.o ../scintilla/gtk/LexEiffel.o ../scintilla/gtk/LexErlang.o ../scintilla/gtk/LexFlagship.o ../scintilla/gtk/LexForth.o ../scintilla/gtk/LexFortran.o ../scintilla/gtk/LexGAP.o ../scintilla/gtk/LexGui4Cli.o ../scintilla/gtk/LexHTML.o ../scintilla/gtk/LexHaskell.o ../scintilla/gtk/LexInno.o ../scintilla/gtk/LexKVIrc.o ../scintilla/gtk/LexKix.o ../scintilla/gtk/LexLaTeX.o ../scintilla/gtk/LexLisp.o ../scintilla/gtk/LexLout.o ../scintilla/gtk/LexLua.o ../scintilla/gtk/LexMMIXAL.o ../scintilla/gtk/LexMPT.o ../scintilla/gtk/LexMSSQL.o ../scintilla/gtk/LexMagik.o ../scintilla/gtk/LexMarkdown.o ../scintilla/gtk/LexMatlab.o ../scintilla/gtk/LexMetapost.o ../scintilla/gtk/LexModula.o ../scintilla/gtk/LexMySQL.o ../scintilla/gtk/LexNimrod.o ../scintilla/gtk/LexNsis.o ../scintilla/gtk/LexOScript.o ../scintilla/gtk/LexOpal.o ../scintilla/gtk/LexOthers.o ../scintilla/gtk/LexPB.o ../scintilla/gtk/LexPLM.o ../scintilla/gtk/LexPO.o ../scintilla/gtk/LexPOV.o ../scintilla/gtk/LexPS.o ../scintilla/gtk/LexPascal.o ../scintilla/gtk/LexPerl.o ../scintilla/gtk/LexPowerPro.o ../scintilla/gtk/LexPowerShell.o ../scintilla/gtk/LexProgress.o ../scintilla/gtk/LexPython.o ../scintilla/gtk/LexR.o ../scintilla/gtk/LexRebol.o ../scintilla/gtk/LexRuby.o ../scintilla/gtk/LexRust.o ../scintilla/gtk/LexSML.o ../scintilla/gtk/LexSQL.o ../scintilla/gtk/LexSTTXT.o ../scintilla/gtk/LexScriptol.o ../scintilla/gtk/LexSmalltalk.o ../scintilla/gtk/LexSorcus.o ../scintilla/gtk/LexSpecman.o ../scintilla/gtk/LexSpice.o ../scintilla/gtk/LexTACL.o ../scintilla/gtk/LexTADS3.o ../scintilla/gtk/LexTAL.o ../scintilla/gtk/LexTCL.o ../scintilla/gtk/LexTCMD.o ../scintilla/gtk/LexTeX.o ../scintilla/gtk/LexTxt2tags.o ../scintilla/gtk/LexVB.o ../scintilla/gtk/LexVHDL.o ../scintilla/gtk/LexVerilog.o ../scintilla/gtk/LexVisualProlog.o ../scintilla/gtk/LexYAML.o ../scintilla/gtk/LexerBase.o ../scintilla/gtk/LexerModule.o ../scintilla/gtk/LexerSimple.o ../scintilla/bin/scintilla.a -o bait -lstdc++ `pkg-config --libs gtk+-2.0 gthread-2.0`
Undefined symbols for architecture x86_64:
"_g_module_close", referenced from:
DynamicLibraryImpl::~DynamicLibraryImpl() in scintilla.a(PlatGTK.o)
"_g_module_open", referenced from:
DynamicLibrary::Load(char const*) in scintilla.a(PlatGTK.o)
"_g_module_symbol", referenced from:
DynamicLibraryImpl::FindFunction(char const*) in scintilla.a(PlatGTK.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [bait] Error 1
There is a ../scintilla/include directory with the Scintilla header files in it.
Try adding -lgmodule to cflags
I am a newbie in C... I wrote a very simple modbus1.c that includes libmodbus (whose source I downloaded, unzipped, untarred, ./configure'd, make'd and make install'd successfully).
When I try to make modbus1.c I get this:
cc -Wall -g modbus1.c -o modbus1
Undefined symbols for architecture x86_64:
"_modbus_close", referenced from:
_main in modbus1-6cd135.o
"_modbus_connect", referenced from:
_main in modbus1-6cd135.o
"_modbus_free", referenced from:
_main in modbus1-6cd135.o
"_modbus_new_tcp_pi", referenced from:
_main in modbus1-6cd135.o
"_modbus_read_bits", referenced from:
_main in modbus1-6cd135.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [modbus1] Error 1
I am running OSX snow leopard and have successfully used make to compile small programs before (tutorial level programs...) Here is the modbus1.c I am trying to compile:
#include <stdio.h>
#include <stdlib.h>
#include <modbus.h>
int main(int argc, char *argv[]){
modbus_t *plc_client;
plc_client = modbus_new_tcp_pi("192.168.1.230","502");
if (plc_client == NULL) {
fprintf(stderr, "Unable to allocate libmodbus context\n");
return -1;
}
if (modbus_connect(plc_client) == -1) {
fprintf(stderr, "Connection failed: \n");
modbus_free(plc_client);
return -1;
}
else if(modbus_connect(plc_client) == 0) {
printf("MODBUS CONNECTION SUCCESSFUL\n");
}
uint8_t* catcher = malloc(sizeof(uint8_t));
if(modbus_read_bits(plc_client, 2000, 1, catcher)>0){
printf("READ SUCCESSFUL");
}
else{
printf("READ FAILED");
}
free(catcher);
modbus_close(plc_client);
modbus_free(plc_client);
return 0;
}
Any help will be greatly appreciated! Thanks!
-Niko
Try this
cc -Wall -g modbus1.c -o modbus1 -L/path/to/libmodbus -lmodbus
You should replace that /path/to/libmodbus with the actual path of directory that includes the libmodbus.dylib in your system.